|
| 1 | +{ |
| 2 | + "title": "Streaming chat with AWS AppSync Events and Amazon Bedrock AgentCore", |
| 3 | + "description": "Stream AI agent responses in real time using AWS AppSync Events WebSockets, two-phase AWS Lambda functions, and Amazon Bedrock AgentCore Runtime.", |
| 4 | + "language": "Python", |
| 5 | + "level": "300", |
| 6 | + "framework": "AWS CDK", |
| 7 | + "introBox": { |
| 8 | + "headline": "How it works", |
| 9 | + "text": [ |
| 10 | + "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.", |
| 11 | + "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.", |
| 12 | + "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." |
| 13 | + ] |
| 14 | + }, |
| 15 | + "gitHub": { |
| 16 | + "template": { |
| 17 | + "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/appsync-events-lambda-agentcore-cdk", |
| 18 | + "templateURL": "serverless-patterns/appsync-events-lambda-agentcore-cdk", |
| 19 | + "projectFolder": "appsync-events-lambda-agentcore-cdk", |
| 20 | + "templateFile": "cdk/stack.py" |
| 21 | + } |
| 22 | + }, |
| 23 | + "resources": { |
| 24 | + "bullets": [ |
| 25 | + { |
| 26 | + "text": "AppSync Events API", |
| 27 | + "link": "https://docs.aws.amazon.com/appsync/latest/eventapi/event-api-welcome.html" |
| 28 | + }, |
| 29 | + { |
| 30 | + "text": "Amazon Bedrock AgentCore", |
| 31 | + "link": "https://docs.aws.amazon.com/bedrock/latest/userguide/agentcore.html" |
| 32 | + } |
| 33 | + ] |
| 34 | + }, |
| 35 | + "deploy": { |
| 36 | + "text": [ |
| 37 | + "python -m venv .venv && source .venv/bin/activate", |
| 38 | + "pip install -r requirements.txt", |
| 39 | + "cdk bootstrap", |
| 40 | + "cdk deploy" |
| 41 | + ] |
| 42 | + }, |
| 43 | + "testing": { |
| 44 | + "text": [ |
| 45 | + "See the GitHub repo for detailed testing instructions using the AppSync Pub/Sub Editor and automated tests." |
| 46 | + ] |
| 47 | + }, |
| 48 | + "cleanup": { |
| 49 | + "text": [ |
| 50 | + "Delete the stack: <code>cdk destroy</code>." |
| 51 | + ] |
| 52 | + }, |
| 53 | + "authors": [ |
| 54 | + { |
| 55 | + "name": "Pete Davis", |
| 56 | + "image": "https://github.com/pjdavis-aws.png", |
| 57 | + "bio": "Senior Partner Solution Architect at AWS", |
| 58 | + "linkedin": "peter-davis-2676585" |
| 59 | + } |
| 60 | + ], |
| 61 | + "patternArch": { |
| 62 | + "icon1": { |
| 63 | + "x": 5, |
| 64 | + "y": 50, |
| 65 | + "service": "icon-internet", |
| 66 | + "label": "Client" |
| 67 | + }, |
| 68 | + "icon2": { |
| 69 | + "x": 30, |
| 70 | + "y": 50, |
| 71 | + "service": "appsync", |
| 72 | + "label": "AWS AppSync Events" |
| 73 | + }, |
| 74 | + "icon3": { |
| 75 | + "x": 55, |
| 76 | + "y": 20, |
| 77 | + "service": "lambda", |
| 78 | + "label": "AWS Lambda" |
| 79 | + }, |
| 80 | + "icon4": { |
| 81 | + "x": 55, |
| 82 | + "y": 68, |
| 83 | + "service": "lambda", |
| 84 | + "label": "AWS Lambda" |
| 85 | + }, |
| 86 | + "icon5": { |
| 87 | + "x": 83, |
| 88 | + "y": 68, |
| 89 | + "service": "bedrock-agentcore", |
| 90 | + "label": "Amazon Bedrock AgentCore" |
| 91 | + }, |
| 92 | + "line1": { |
| 93 | + "from": "icon1", |
| 94 | + "to": "icon2", |
| 95 | + "label": "Subscribe/chat" |
| 96 | + }, |
| 97 | + "line2": { |
| 98 | + "from": "icon2", |
| 99 | + "to": "icon3", |
| 100 | + "label": "Invoke chat" |
| 101 | + }, |
| 102 | + "line4": { |
| 103 | + "from": "icon4", |
| 104 | + "to": "icon5", |
| 105 | + "label": "Invoke agent" |
| 106 | + }, |
| 107 | + "line5": { |
| 108 | + "from": "icon2", |
| 109 | + "to": "icon4", |
| 110 | + "label": "Results" |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments