Amazon API Gateway to AWS Lambda to Amazon Bedrock

API Gateway → AWS Lambda → Amazon Bedrock

Make a request to Bedrock via API Gateway.

Amazon API Gateway receives the HTTP POST request containing the prompt.
AWS Lambda is triggered by the API Gateway endpoint. This function forwards the prompt to Amazon Bedrock API using the AWS SDK for JavaScript bedrock-runtime API. It uses the Anthropic Claude-v2 model and sets other required parameters to fixed values for simplicity.
Based on the given prompt, using the Anthropic Claude-v2 model, Amazon Bedrock generates the content and returns the response to Lambda.
Lambda processes the Bedrock output and sends it back to the user via API Gateway.

< 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-js-sam

Deploy

sam deploy --guided./create_lambda_layer.sh


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: sam delete.
2. Delete Lambda layer stack: ./delete_lambda_layer.sh.

Additional resources

Created by:

Saborni Bhattacharya

Saborni Bhattacharya

AWS SA, Cloud Enthusiast

Follow on LinkedIn