Streaming chat with AWS AppSync Events and Amazon Bedrock AgentCore

Client → AWS AppSync Events → AWS Lambda → AWS Lambda → Amazon Bedrock AgentCore

Stream AI agent responses in real time using AWS AppSync Events WebSockets, two-phase AWS Lambda functions, and Amazon Bedrock AgentCore Runtime.

This pattern deploys a real-time streaming chat service using AWS AppSync Events with a two-phase Lambda architecture to invoke a Strands agent running on Amazon Bedrock AgentCore Runtime.
The client publishes messages to an inbound channel via HTTP. AppSync Events triggers an agent invoker Lambda via direct Lambda integration (synchronous only), which asynchronously invokes a separate stream relay Lambda function, then returns immediately. Two Lambda functions are needed because AppSync Events requires a synchronous function invocation, so the invoker must return quickly. The stream relay calls the AgentCore Runtime, consumes the Server-Sent Events (SSE) stream, and publishes response chunks back to a separate response channel.
The client receives agent response tokens in real time via a WebSocket subscription. Separate channel namespaces for inbound and outbound traffic prevent re-invocation loops.

< 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-events-lambda-agentcore-cdk

Deploy

python -m venv .venv && source .venv/bin/activatepip install -r requirements.txtcdk bootstrapcdk deploy


Testing

See the GitHub repo for detailed testing instructions using the AppSync Pub/Sub Editor and automated tests.

Cleanup

Delete the stack: cdk destroy.

Created by:

Pete Davis

Pete Davis

Senior Partner Solution Architect at AWS

Follow on LinkedIn