This pattern deploys an AWS AppSync Events API with a Direct Lambda OnPublish interceptor — a Lambda function that intercepts, validates, and enriches events in-flight before they reach subscribers. Unlike the existing appsync-events-bedrock-cdk and appsync-events-lambda-agentcore-cdk patterns (which use Lambda as a publisher), this pattern uses Lambda as a real-time event processor wired directly into the AppSync channel namespace.
Use cases: payload validation, PII redaction, event enrichment with external data, rate limiting per publisher, and schema enforcement before delivery.
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/appsync-events-lambda-cdk
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details.
- AWS CLI installed and configured
- Node.js 22+ installed
- AWS CDK v2 installed
- Publishers send events via HTTP POST to the AWS AppSync Events endpoint.
- The AWS Lambda function processes and enriches events before delivery.
- AWS AppSync Events delivers messages to all WebSocket subscribers on that channel.
- Channel namespaces (
notifications,alerts) organize topics.
-
Clone the repository and navigate to the pattern directory:
git clone https://github.com/aws-samples/serverless-patterns cd serverless-patterns/appsync-events-lambda-cdk -
Install dependencies:
npm install
-
Bootstrap CDK (one-time per account/region):
cdk bootstrap
-
Deploy the stack:
cdk deploy
# Publish an event (replace values from cdk deploy output)
curl -X POST "https://<HttpEndpoint>/event" \
-H "x-api-key: <ApiKeyValue>" \
-H "Content-Type: application/json" \
-d '{"channel":"notifications/general","events":["{\"message\":\"Hello from CDK\"}"]}'cdk destroy