We use AWS Lambda and AWS Bedrock to summarize text documents. When a text file is uploaded to an S3 bucket, a Lambda function will be triggered to send the file content to a language model on AWS Bedrock. The language model will produce a summary of the content (including 3 keywords and a summary) which the Lambda function will output to another S3 bucket.
This is a simplified version of the application built in the following course "Serverless LLM apps with Amazon Bedrock" by DeepLearning.AI https://www.deeplearning.ai/short-courses/.
Instructions:
- Ensure you're in 'us-west-2' region. Please note we will use AWS Bedrock. See here for the supported regions https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html
- In the AWS Bedrock console, request access for the model titan-text-express-v1.
- Create two S3 buckets: input_bucket, output_bucket.
- Deploy lambda_function.py and prompt_template.txt as a Lambda function on AWS.
- Ensure Timeout for the Lambda function is set to 2 min.
- Ensure the Lambda function has the right permission to interact with AWS Bedrock and S3. A CloudFormation template lambda_role.yaml is included for your reference. You can use it to create the required role if needed.
- Add input_bucket as the trigger for the Lambda function, set output_bucket as an environment variable for the Lambda function.
- Create a Lambda layer and upload the file lambda-bedrock-layer.zip, add the layer to the Lambda function by specifying its ARN.
- Test by uploading a text file to input_bucket.