Skip to content

New serverless pattern - eventbridge-webhook-sfn-typescript-cdk - #3563

Open
NithinChandranR-AWS wants to merge 1 commit into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-eventbridge-webhook-sfn-cdk
Open

NithinChandranR-AWS wants to merge 1 commit into
aws-samples:mainfrom
NithinChandranR-AWS:NithinChandranR-AWS-feature-eventbridge-webhook-sfn-cdk

Conversation

@NithinChandranR-AWS

Copy link
Copy Markdown
Contributor

Description

Amazon EventBridge Webhook Events to AWS Step Functions and Amazon DynamoDB. A third-party provider posts HMAC-signed webhooks to an HTTPS URL that EventBridge hosts; EventBridge checks the signature and timestamp, drops repeated content and puts each body on a Custom Event Bus, and a subscriber starts a Step Functions workflow that stores each known event once in DynamoDB. There is no Amazon API Gateway, Lambda function URL or verifier function. Claim issue: #3562.

Key Innovation

First pattern with an EventBridge webhook event source (AWS::EventsV2::EventSource), and the first Custom Event Bus subscriber that targets Step Functions. The existing eventbridge-webhooks family runs a Lambda function URL and a verifier function; this one has no ingest compute, so it is a new family rather than a variant.

Architecture

Provider (HMAC-SHA256 over timestamp.body) -> Amazon EventBridge webhook event source (signature, timestamp, content-based dedup) -> Custom Event Bus -> subscriber (filter, batches of up to 10) -> AWS Step Functions (Map, Choice) -> Amazon DynamoDB conditional PutItem

Deployed and Tested

Stack deploys in us-west-2 (~90 s) and us-east-1 (~120 s), 11 CloudFormation resources, no AWS Lambda function. README Testing run as written in zsh and bash 3.2 (us-west-2) and zsh (us-east-1), identical output:

  • Unsigned and wrongly signed requests: 403; a signed request 15 minutes old: 403.
  • Signed order.created: 200, one execution SUCCEEDED with stored, item read back from DynamoDB with that execution ARN.
  • The same signed request again: 200 and still one execution (content-based deduplication).
  • Same event id with a different body: 200, second execution reports duplicate, the item keeps the first execution ARN.
  • Unknown type reported ignored; a body without id is not delivered by the subscriber filter.
  • Cleanup: the stack and the EventBridge-created secret are gone; nothing is left.

Checklist

  • IAM least-privilege (webhook role: events:PutWebhookEvents on the bus and secretsmanager:GetSecretValue on secret:events-webhook!*; subscriber role: states:StartExecution on the one state machine; workflow role: dynamodb:PutItem on the table; trust policies with aws:SourceAccount and aws:SourceArn)
  • CDK synth passes (11 resources; the webhook configuration is set with addPropertyOverride because aws-cdk-lib 2.278.0 does not type it yet)
  • Deployed and tested end-to-end in us-west-2 and us-east-1
  • validate.js passes, including the admin IAM check
  • No duplicate patterns in repo

…Webhook Events to AWS Step Functions

- Webhook event source (HMAC-SHA256 over timestamp.body, 300 s tolerance, content-based dedup) on an EventBridge Custom Event Bus
- Subscriber with a DATA filter and batches of up to 10 starts a Standard JSONata workflow
- Map over the batch: known types with a string or number id go to a conditional DynamoDB PutItem (stored or duplicate), others are ignored, write errors end in a Fail state
- Scoped permissions: PutWebhookEvents on the bus, GetSecretValue on the source's own secret, StartExecution on the state machine, PutItem on the table
- Role trusts carry aws:SourceAccount and aws:SourceArn conditions (live-tested: signed requests are delivered)
- README with signed curl tests for 403, 200, dedup, idempotent write, filter and stale timestamp

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants