-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Use the model template located at https://github.com/aws-samples/serverless-patterns/tree/main/_pattern-model to set up a README, template and any associated code.
Description (mid-length e.g. "Create a Lambda function that sends events to EventBridge.")
This pattern demonstrates how to implement long-running invocations with Amazon Bedrock using AWS AppSync subscriptions and AWS Lambda in Event Mode, following the official AWS AppSync documentation pattern.
Language: (optional e.g. "Python", if you have a Lambda function in your example)
Typescript
YouTube videoId (optional e.g. "VI79XQW4dIM")
Framework (currently we support SAM or CDK)
CDK
Services from/to (e.g. "Lambda to EventBridge)
AppSync to Lambda to Bedrock Streaming
Description (this must include a throughout explanation of the pattern together with details of IAM permissioning)
The pattern implements an asynchronous streaming architecture where:
- Client initiates a WebSocket subscription and makes a request to AppSync
- AppSync invokes Lambda function in Event mode, enabling asynchronous processing
- Lambda function streams responses from Bedrock using ConverseStream
- Lambda sends updates via mutations to AppSync
- Updates are delivered to client through WebSocket subscription
Key Benefits
- Asynchronous Processing: AppSync immediately returns a response while Lambda processes the request asynchronously, preventing timeouts for long-running operations
- Real-time Updates: Clients receive progressive updates through WebSocket subscriptions as the model generates responses
- Scalable Architecture: Event-driven design allows handling multiple concurrent requests without blocking
- Enhanced User Experience: Progressive updates enable responsive interfaces even during lengthy AI model invocations
Deployment commands
- Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/serverless-patterns- Change directory to the pattern directory:
cd appsync-lambda-bedrock-async-stream-subscription-cdk- Install the required dependencies:
npm install- Deploy the stack to your default AWS account and region:
npm run deployTesting
After deployment, you can test the Bedrock streaming integration using the provided test script. The script demonstrates:
- WebSocket subscription initialization
- Conversation start with Bedrock
- Real-time streaming chunks display
- Graceful cleanup on exit
Run the test script using:
npx tsx test/test.ts GitHub PR for template:
Payload example (e.g. Lambda event payload from source service).
N/A
Additional resources (optional: link and anchor text, up to 5 resources)
Author bio
Name: Kaustav Dey
Photo URL: https://github.com/kaustavbecs.png
Twitter handle: n/a
LinkedIn: https://www.linkedin.com/in/kaustavbecs/
Description (up to 255 chars): I am a Solutions Architect working for AWS.