WebSocket API to AWS Lambda to Amazon Bedrock with streaming response

API Gateway WebSocket API → AWS Lambda → Amazon Bedrock

Creates an API Gateway WebSocketand Lambda functions that provides a streaming response from the LLMs in Amazon Bedrock.

This sample project demonstrates how to use WebSocket API as a front door to Lambda functions that perform inference on Amazon Bedrock LLMs using the [InvokeModelWithResponseStream API, where the LLM responses are returned in a stream.
With WebSocket API, developers of interactive LLM chatbot interfaces can provide a better user experience by displaying the LLM responses as they are generated (which at times can be long, rather than relying on the synchronous InvokeModel API request.
This pattern deploys one API Gateway WebSocket API, four Lambda functions, and one DynamoDB table.

< 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-websocket-api-bedrock-streaming

Deploy

sam deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: sam delete --stack-name STACK_NAME.

Created by:

Windrich

I am a Solutions Architect in AWS who works with customers in industries such as finance and transport, to help accelerate their cloud adoption journey. He is especially interested in Serverless technologies and how customers can leverage them to bring values to their business.

Follow on LinkedIn