Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 2.34 KB

File metadata and controls

65 lines (46 loc) · 2.34 KB

AppSync Events — In-Flight Event Interception with AWS Lambda

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.

Requirements

Architecture

Architecture Diagram

How it works

  1. Publishers send events via HTTP POST to the AWS AppSync Events endpoint.
  2. The AWS Lambda function processes and enriches events before delivery.
  3. AWS AppSync Events delivers messages to all WebSocket subscribers on that channel.
  4. Channel namespaces (notifications, alerts) organize topics.

Deployment

  1. 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
  2. Install dependencies:

    npm install
  3. Bootstrap CDK (one-time per account/region):

    cdk bootstrap
  4. Deploy the stack:

    cdk deploy

Testing

# 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\"}"]}'

Cleanup

cdk destroy