AWS EventBridge Cheat Sheet
Event bus rules, patterns, schedules, and SDK snippets for routing events between AWS services and SaaS apps.
Create a Rule with an Event Pattern
Route events matching a pattern to a target using the AWS CLI.
# Create a rule that matches EC2 instance state changesaws events put-rule \ --name "ec2-state-change" \ --event-pattern '{ "source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": { "state": ["running", "stopped"] } }'# Attach a Lambda function as the targetaws events put-targets \ --rule "ec2-state-change" \ --targets '[{"Id": "1", "Arn": "arn:aws:lambda:us-east-1:123456789012:function:notify"}]'# Grant EventBridge permission to invoke the Lambdaaws lambda add-permission \ --function-name notify \ --statement-id eventbridge-invoke \ --action lambda:InvokeFunction \ --principal events.amazonaws.com \ --source-arn arn:aws:events:us-east-1:123456789012:rule/ec2-state-change
Custom Event Bus & PutEvents (SDK)
Publish a custom application event to a dedicated event bus using boto3.
import boto3, jsonclient = boto3.client("events")response = client.put_events( Entries=[ { "Source": "myapp.orders", "DetailType": "OrderPlaced", "Detail": json.dumps({"orderId": "o-123", "total": 49.99}), "EventBusName": "orders-bus", } ])print(response["Entries"]) # check for EventId / ErrorCode per entry
Scheduled Rule (cron / rate)
Trigger a target on a fixed schedule instead of an event pattern.
# Every 15 minutesaws events put-rule \ --name "poll-every-15-min" \ --schedule-expression "rate(15 minutes)"# Cron: 8am UTC every weekdayaws events put-rule \ --name "weekday-morning-report" \ --schedule-expression "cron(0 8 ? * MON-FRI *)"
Core Concepts
The building blocks of EventBridge you'll reference constantly.
- Event bus- a router that receives events; default, custom, or partner (SaaS) buses
- Rule- matches events via an event pattern or a schedule expression
- Target- up to 5 destinations per rule (Lambda, SQS, SNS, Step Functions, etc.)
- Event pattern- JSON filter matched against source, detail-type, and detail fields
- Archive & Replay- store matched/unmatched events and replay them into a bus later
- Schema registry- infers and stores JSON schemas for events flowing through a bus
- Input transformer- reshapes the event JSON before it reaches the target
Dead-Letter Queue & Retry Policy on a Target
Configure bounded retries and a DLQ so failed target invocations aren't silently dropped after EventBridge's default retry window.
aws events put-targets \ --rule "ec2-state-change" \ --targets '[{ "Id": "1", "Arn": "arn:aws:lambda:us-east-1:123456789012:function:notify", "RetryPolicy": { "MaximumRetryAttempts": 3, "MaximumEventAgeInSeconds": 3600 }, "DeadLetterConfig": { "Arn": "arn:aws:sqs:us-east-1:123456789012:notify-dlq" } }]'
EventBridge Pipes: Source-to-Target with Enrichment
Pipes connect a source directly to a target with optional filter/enrichment/transform steps, avoiding a Lambda glue function for simple point-to-point routing.
aws pipes create-pipe \ --name "orders-to-stepfunctions" \ --source "arn:aws:sqs:us-east-1:123456789012:orders-queue" \ --target "arn:aws:states:us-east-1:123456789012:stateMachine:ProcessOrder" \ --role-arn "arn:aws:iam::123456789012:role/pipes-role" \ --source-parameters '{"SqsQueueParameters": {"BatchSize": 10}}' \ --enrichment "arn:aws:lambda:us-east-1:123456789012:function:enrichOrder" \ --target-parameters '{"StepFunctionStateMachineParameters": {"InvocationType": "FIRE_AND_FORGET"}}'
Schema Discovery & Type-Safe Bindings
Enable the schema registry on a bus and generate strongly-typed handler code for a matched event, instead of hand-writing detail interfaces.
# Turn on schema discovery for a custom bus (samples matched events, infers JSON Schema)aws schemas start-discoverer \ --source-arn arn:aws:events:us-east-1:123456789012:event-bus/orders-bus# Generate a strongly-typed binding (e.g. Java/TS/Python) once a schema existsaws schemas get-code-binding-source \ --registry-name discovered-schemas \ --schema-name myapp.orders@OrderPlaced \ --language TypeScript3 output.zip
Cross-Account Event Bus Resource Policy
Allow another AWS account to publish events onto your bus, a common pattern for centralized security/ops event aggregation.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowAccountToPutEvents", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::999988887777:root" }, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/central-security-bus", "Condition": { "StringEquals": { "events:source": "aws.guardduty" } } } ]}
Advanced Operational Concepts
Things that matter once you're running EventBridge in production at scale, beyond the core bus/rule/target model.
- Event age & delivery orderingEventBridge does not guarantee delivery order across events; design consumers to be idempotent and order-tolerant, using timestamps in the payload if sequencing matters
- At-least-once deliverytargets can receive the same event more than once during retries; downstream Lambdas/queues must dedupe on an idempotency key
- Pipes vs. Rules+LambdaPipes avoid the cost and cold-start latency of a glue Lambda for simple enrich-and-forward flows, but Rules give more flexible fan-out to 5 targets
- Archive replay windowsreplays reprocess a time range from an archive at up to 1000x speed but respect the original rule's target — useful for backfilling a newly-added consumer
- Schema registry discoverer costthe discoverer samples a percentage of events, not all of them, to control cost; disable it once schemas stabilize to avoid ongoing charges
- Global endpoints & failoverglobal endpoints replicate events to a secondary region's bus and can auto-failover PutEvents traffic based on a CloudWatch health check alarm
Use content filtering operators like `anything-but`, `prefix`, and `numeric` ranges in event patterns instead of chaining multiple rules — it cuts costs and keeps routing logic in one place.