Amazon API Gateway to AWS Lambda to Amazon Bedrock

API Gateway REST API → AWS Lambda → Amazon Bedrock

Make a request to Bedrock via API Gateway using Java and CDK

Amazon API Gateway receives the HTTP POST request containing the prompt.
AWS Lambda is triggered by API Gateway, this function forwards the prompt to Amazon Bedrock API using AWS SDK for Java. It uses Anthropic Claude-v2 model and sets other required parameters to fixed values for simplicity.
Based on the given prompt, using 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 the 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 apigw-lambda-bedrock-cdk-java

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: cdk delete.

Additional resources

Created by:

Grzegorz Kozub

Grzegorz Kozub

Cloud Application Architect working at AWS Professional Services.

Follow on LinkedIn