Amazon API Gateway response streaming with AWS Lambda integration

Amazon API Gateway REST API → AWS Lambda → Amazon Bedrock

This sample project demonstrates how to deploy Amazon API Gateway REST API with response streaming for AWS Lambda backend.

Amazon API Gateway receives the HTTP POST request containing the prompt.
The API Gateway triggers the Lambda functions which use either InvokeModelWithResponseStreamCommand or InvokeModelCommand to call Bedrock for streaming and non-streaming use cases.
The foundation model in Bedrock generates content and streams or returns the response to the respective Lambda functions.
The API Gateway either streams the responses back to the client or returns the whole response together.

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

Deploy

sam buildsam deploy --guided


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: sam delete.

Created by:

Biswanath Mukherjee

Biswanath Mukherjee

Sr. Solutions Architect working at AWS India.

Follow on LinkedIn

Giedrius Praspaliauskas

Giedrius Praspaliauskas

Giedrius is a senior solutions architect focusing on serverless at Amazon Web Services based in the US.

Follow on LinkedIn