Amazon API Gateway - AWS Lambda - Amazon Bedrock

Amazon API Gateway → AWS Lambda → Amazon Bedrock

Interact with Bedrock models from a Lambda function fronted with an API Gateway

This project builds an integration between Amazon API Gateway, AWS Lambda, and Amazon Bedrock
The core functionality revolves around exposing an API endpoint via API Gateway that accepts a user-defined prompt.
When a prompt is received, the API Gateway triggers an AWS Lambda function. This Lambda function is responsible for invoking a model (anthropic.claude-v2 for now, but can be extended to include others) hosted on Amazon Bedrock.
To ensure compatibility with Bedrock, a Lambda Layer is utilized, it contains the latest version of the Boto3 library, as only the most recent Boto3 version includes a client for Amazon Bedrock.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/apigw-lambda-bedrock-cdk-python

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: npx cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Created by:

Guillermo Mansilla

Guillermo Mansilla

Guillermo Mansilla is a Solutions Architect based in Orlando, Florida. He has helped startups in the USA and Canada build and architect their applications on AWS. Before joining AWS, Guillermo spent over a decade working as a Software Developer. When he’s not at his desk, you can find him playing chess tournaments at his local chess club.

Follow on LinkedIn