AI Chat with AWS AppSync (WebSockets), AWS Lambda, and Amazon Bedrock

AWS AppSync GraphQL API → AWS Lambda → Amazon Bedrock

WebSocket-Enabled AI Chat Using AWS Services.

This AI chat application works through a simple request-response flow.
A client sends a GraphQL mutation to the AWS AppSync API endpoint.
AWS AppSync then routes the request to a AWS Lambda function via the configured data source and resolver.
The AWS Lambda function receives the user's input message, constructs a properly formatted request for Amazon Bedrock's Claude model (including the Anthropic API version, token limit, and user message).
Then sends it to Amazon Bedrock using the AWS SDK, waits for the AI response, and returns the generated text back to AWS AppSync.
AWS AppSync then delivers this response to the client, while the subscription feature enables real-time notifications to connected clients when new responses are available, creating an interactive chat experience where users can send messages and receive AI-generated replies in real-time.

< 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/appsync-ws-lambda-bedrock-sam

Deploy

sam deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

sam delete

Created by:

Mike Hume

Mike Hume

AWS Senior Solutions Architect & UKPS Serverless Lead.

Follow on LinkedIn