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 sends the prompt to Amazon Bedrock with the Converse API in the AWS SDK for Java. It calls Anthropic Claude Haiku 5.5 through the global cross-Region inference profile, with a fixed output token limit for simplicity.
Based on the given prompt, Anthropic Claude Haiku 5.5 in 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

Variants

This pattern is available in the following frameworks/languages:

AWS CDK:JavaPython

Clone repo

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

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: cdk destroy.

Additional resources

Created by:

Grzegorz Kozub

Grzegorz Kozub

Cloud Application Architect working at AWS Professional Services.