Quite recently I watched a short course created by DeepLearning.AI titled “Serverless LLM apps with Amazon Bedrock“. It is a very good course for beginners, well crafted, with good examples, and clear explanations by Mike Chambers. He goes and creates a small app using AWS Lambda, AWS S3, and Amazon Bedrock that does text summarisation of recorded conversations. I wanted to add something to the topic and provide a fully working example you can deploy easily using AWS CDK.
AWS Cloud Development Kit is what Tiggers like best, it is infrastructure as a code (IaaC) framework provided by AWS. Infrastructure can be defined using Python, TypeScript, Java, .NET, and Go.
The course does not have IaaC and for a good reason. It would muddy the water and make things harder to grasp for newcomers. I have lifted the code from the course to add infrastructure definition in Python. This way no helpers from the course are required, and it can be easily deployed with AWS CDK cli.
Code
Code is stored on Github.
The stack includes:
- S3 bucket for audio files
- S3 bucket for summarised text
- Lambda function to transcribe audio files
- Lambda function to summarise a transcribed text
- Lambda layer for summarisation function
- IAM roles and policies for Lambda functions
Deployment and verification
Following steps are lifted from the README of the repository. I use them here to illustrate how easy it is to deploy the whole solution.
- Clone the repository.
- Create python virtual environment
python -m venv .venv
- Activate virtual environment
source .venv/bin/activate
. On Windows, use.\.venv\Scripts\Activate.ps1
. - Install dependencies,
pip install -r requirements.txt
- Deploy the stack
cdk deploy
- After deployment is complete, you will see all resources created in your AWS account.
Since you have aws-cli
so you may use it to verify if the code works.
# Check for S3 buckets
aws s3 ls | grep cdkllm
# Check for Lambda functions
aws lambda list-functions --query 'Functions[].FunctionName' --no-cli-pager | grep -i cdkllm
# Check for Lambda layer
aws lambda list-layers --query 'Layers[].LayerName' --no-cli-pager | grep -i llm
# You can also test the stack by uploading an audio file to the S3 bucket created and check the output in the S3 bucket.
# Upload audio file to S3
aws s3 cp <path_to_audio_file> s3://<bucket_name>
# Check the output in the S3 bucket
aws s3 ls s3://<bucket_name>/summaries/
# Download the output
aws s3 cp s3://<bucket_name>/summaries/ .
Code language: Bash (bash)
Thank you for reading till the end. I encourage you to take the course “Serverless LLM apps with Amazon Bedrock” as well as play around with this code.