[{"data":1,"prerenderedAt":74},["ShallowReactive",2],{"pattern-appsync-events-lambda-typescript-cdk":3,"pattern-group-appsync-events-lambda-typescript-cdk":6},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":11,"deploy":13,"description":17,"extension":18,"framework":19,"gitHub":20,"highlight":6,"introBox":24,"language":30,"level":31,"meta":32,"patternArch":33,"patternGroup":6,"patternGroupLabel":6,"resources":61,"stem":69,"testing":70,"videoId":6,"__hash__":73},"patterns\u002Fpatterns\u002Fappsync-events-lambda-typescript-cdk.json","AWS AppSync Events with an AWS Lambda OnPublish handler",null,{"text":8},[9,10],"\u003Ccode>npx cdk destroy\u003C\u002Fcode>","Delete the log group that AWS AppSync creates outside the stack: \u003Ccode>aws logs delete-log-group --log-group-name \u002Faws\u002Fappsync\u002Fapis\u002F&lt;ApiId&gt;\u003C\u002Fcode>",[12],"content\u002Fcontributors\u002Fnithin-chandran-r.json",{"text":14},[15,16],"\u003Ccode>npm install\u003C\u002Fcode>","\u003Ccode>npx cdk deploy\u003C\u002Fcode>","Validate and enrich events in an AWS Lambda function before AWS AppSync Events delivers them to WebSocket subscribers.","json","AWS CDK",{"template":21},{"patternPath":22,"templateFile":23},"appsync-events-lambda\u002Ftypescript\u002Fcdk","lib\u002Fappsync-events-lambda-stack.ts",{"headline":25,"text":26},"How it works",[27,28,29],"This pattern deploys an AWS AppSync Events API with a direct Lambda integration on the `notifications` channel namespace. Every event published to a `notifications\u002F...` channel goes to an AWS Lambda function (`REQUEST_RESPONSE`) before AppSync broadcasts it to WebSocket subscribers. The function adds `processedAt`, `enriched` and `messageId` fields, and returns an error for a payload that isn't a JSON object.","Use the same hook to validate payloads, redact personal data or add data from another source. A second namespace, `alerts`, has no handler, so you can compare intercepted and plain delivery.","Publishers and subscribers authenticate with an API key that the stack creates with a 365-day expiry. The stack doesn't output the key, so read it with `aws appsync list-api-keys`.","TypeScript","300",{},{"icon1":34,"icon2":39,"icon3":43,"icon4":48,"line1":51,"line2":55,"line3":58},{"x":35,"y":36,"service":37,"label":38},12,45,"icon-internet","Client",{"x":40,"y":36,"service":41,"label":42},50,"appsync","AWS AppSync\nEvents API",{"x":44,"y":45,"service":46,"label":47},88,20,"lambda-event-functions","AWS Lambda\nOnPublish",{"x":44,"y":49,"service":37,"label":50},68,"Subscribers",{"from":52,"to":53,"label":54},"icon1","icon2","HTTP POST",{"from":53,"to":56,"label":57},"icon3","Validate, enrich",{"from":53,"to":59,"label":60},"icon4","WebSocket",{"bullets":62},[63,66],{"text":64,"link":65},"AWS AppSync Events","https:\u002F\u002Fdocs.aws.amazon.com\u002Fappsync\u002Flatest\u002Feventapi\u002Fevent-api-welcome.html",{"text":67,"link":68},"Direct Lambda integration for AWS AppSync Events","https:\u002F\u002Fdocs.aws.amazon.com\u002Fappsync\u002Flatest\u002Feventapi\u002Fwriting-event-handlers.html#direct-lambda-integration","patterns\u002Fappsync-events-lambda-typescript-cdk",{"text":71},[72],"Subscribe to \u003Ccode>\u002Fnotifications\u002F*\u003C\u002Fcode> in the Pub\u002FSub Editor of the AWS AppSync console, then publish an event to \u003Ccode>notifications\u002Fgeneral\u003C\u002Fcode> with the HTTP endpoint and the API key. The event arrives with the fields the function added. See the README in the GitHub repo for the commands.","kj_dG9Xp1jJzctxOFKkzzZfTQJE7jWdSjav90xuYM-w",1795189148950]