EventBridge: Event Bus and Rules
Publish events to a custom EventBridge bus, write event pattern rules to filter and route events to Lambda, SQS, or Step Functions targets.
EventBridge: Event Bus and Rules is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Amazon EventBridge?
Amazon EventBridge (formerly CloudWatch Events) is a serverless event bus that makes it easy to connect applications using events from AWS services, your own applications, and SaaS providers. Events are JSON objects; EventBridge routes them to one or more targets based on event pattern rules. Unlike SQS (point-to-point), EventBridge is a pub/sub routing layer — one event can fan out to many targets simultaneously.
Event Buses: Default, Custom, and Partner
EventBridge has three types of event buses. The Default bus receives events from AWS services (EC2 state changes, S3 events, CloudTrail API calls, etc.). Custom buses are buses you create for your own application events — they isolate your application events from AWS service events. Partner buses receive events directly from SaaS providers (Zendesk, Datadog, GitHub, Shopify) through pre-built integrations, without needing a polling Lambda.
# Create a custom event bus for your application
aws events create-event-bus --name my-app-bus
# Put a custom event onto the bus
aws events put-events --entries '[{
"Source": "com.myapp.orders",
"DetailType": "OrderPlaced",
"Detail": "{\"orderId\": \"ORD-123\", \"total\": 99.99}",
"EventBusName": "my-app-bus"
}]'Event Pattern Rules
An event pattern rule defines which events to match using a JSON pattern that filters on any combination of event fields (source, detail-type, account, region, or fields inside the detail object). EventBridge evaluates every event against all rules on the bus. Matching events are forwarded to the rule's configured targets. Rules are OR at the rule level and AND within a pattern object.
# Create a rule that matches EC2 instance state changes to 'stopped'
aws events put-rule \
--name ec2-stopped-alert \
--event-bus-name default \
--event-pattern '{
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["stopped"]
}
}' \
--state ENABLEDConfiguring Targets
EventBridge can route matched events to over 20 target types including Lambda functions, SQS queues, SNS topics, Step Functions state machines, Kinesis Data Streams, API Gateway endpoints, ECS tasks, and even another EventBridge bus (for cross-account routing). Each rule can have up to 5 targets. EventBridge invokes targets asynchronously and retries with exponential backoff on failure.
# Add an SNS topic and Lambda function as targets for the rule
aws events put-targets \
--rule ec2-stopped-alert \
--event-bus-name default \
--targets '[{
"Id": "notify-ops",
"Arn": "arn:aws:sns:us-east-1:123456789012:ops-alerts"
}, {
"Id": "auto-remediate",
"Arn": "arn:aws:lambda:us-east-1:123456789012:function:RestartEC2"
}]'Input Transformation
By default, EventBridge passes the entire event JSON to the target. Use Input Transformation to reshape the event before delivery — extract specific fields, construct a new JSON object, or create a custom string. This is useful when a Lambda function or API endpoint expects a specific payload shape rather than the full EventBridge event envelope, avoiding the need for a pass-through Lambda just to reshape data.
# Input transformer: extract orderId and total from detail
# InputPathsMap extracts values by JSON path
{
'InputPathsMap': {
'orderId': '$.detail.orderId',
'total': '$.detail.total'
},
'InputTemplate': '{
"message": "New order <orderId> for $<total>",
"channel": "ops"
}'
}Scheduled Rules (Cron/Rate)
EventBridge rules can also fire on a schedule rather than matching an event. Use a rate expression (e.g., rate(5 minutes)) for fixed-interval triggers, or a cron expression for calendar-based scheduling. Scheduled rules are perfect for triggering Lambda functions for batch cleanup jobs, sending periodic reports, or running nightly DMS tasks — replacing the need for EC2-based cron jobs.
# Create a scheduled rule that fires every day at midnight UTC
aws events put-rule \
--name nightly-cleanup \
--schedule-expression 'cron(0 0 * * ? *)' \
--state ENABLED
aws events put-targets \
--rule nightly-cleanup \
--targets '[{
"Id": "cleanup-lambda",
"Arn": "arn:aws:lambda:us-east-1:123456789012:function:NightlyCleanup"
}]'Event Archive and Replay
EventBridge can archive all events (or a filtered subset) from a bus to an event archive, retaining them for a configurable period. You can then replay archived events back to the bus at any time — useful for replaying events to test a new Lambda version, recover from a bug where a target missed events, or backfill a new service with historical events. This is a powerful operational safety net unique to EventBridge versus other pub/sub systems.
# Create an event archive for the custom bus
aws events create-archive \
--archive-name my-app-archive \
--event-source-arn arn:aws:events:us-east-1:123456789012:event-bus/my-app-bus \
--retention-days 30
# Replay archived events from a specific time window
aws events start-replay \
--replay-name replay-missed-orders \
--event-source-arn arn:aws:events:us-east-1:123456789012:archive/my-app-archive \
--event-start-time 2024-01-10T00:00:00Z \
--event-end-time 2024-01-10T06:00:00Z \
--destination '{"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/my-app-bus"}'Cross-Account and Cross-Region Routing
EventBridge supports cross-account event routing by creating a resource-based policy on the target bus in another account that permits the source account to put events. This enables a centralised monitoring account to receive events from all workload accounts, or a shared service bus architecture where a platform team routes events to consumer team buses. Cross-Region routing works similarly with explicit cross-Region event bus targets.
# Allow a source account (111111111111) to send events to this bus
aws events put-permission \
--event-bus-name my-central-bus \
--action events:PutEvents \
--principal 111111111111 \
--statement-id allow-source-accountEventBridge Pipes
EventBridge Pipes creates point-to-point integrations between a source (SQS, Kinesis, DynamoDB Streams, Kafka) and a target with optional filtering and enrichment in between (via Lambda, Step Functions, or API Gateway). Pipes are simpler than writing a polling Lambda consumer — they handle polling, batching, filtering, and routing automatically. Use Pipes when you need a direct source-to-target connection without a full pub/sub bus.
# Create an EventBridge Pipe from SQS to Lambda
aws pipes create-pipe \
--name sqs-to-processor \
--source arn:aws:sqs:us-east-1:123456789012:incoming-orders \
--target arn:aws:lambda:us-east-1:123456789012:function:ProcessOrder \
--role-arn arn:aws:iam::123456789012:role/PipeRole \
--source-parameters '{
"SqsQueueParameters": {"BatchSize": 10}
}' \
--filter-criteria '{
"Filters": [{"Pattern": "{\"body\": {\"orderType\": [\"PRIORITY\"]}}"}]
}'EventBridge vs SNS vs SQS
These three services overlap but serve different use cases. SNS: push-based fan-out to subscribers (email, HTTP, SQS, Lambda) — simple pub/sub with no filtering. SQS: durable message queue for point-to-point decoupling with consumer-pull semantics. EventBridge: content-based routing bus with schema registry, archive/replay, SaaS partners, and cross-account delivery — best for complex event routing across many services. Use EventBridge when you need sophisticated routing rules, not just simple fan-out.
EventBridge Schema Registry
The EventBridge Schema Registry automatically detects and catalogues the structure of events flowing through your event buses. It stores schemas in OpenAPI 3.0 format so developers can discover what events are available and generate code bindings (Java, Python, TypeScript) that deserialise events into typed objects. This eliminates manual JSON parsing code and ensures type safety across event-driven services. You can also manually register custom event schemas for events produced by your own applications.
# Enable schema discovery on a custom event bus
aws schemas create-discoverer \
--source-arn arn:aws:events:us-east-1:123456789012:event-bus/my-app-bus \
--description 'Auto-discover schemas from app bus'
# List discovered schemas
aws schemas list-schemas \
--registry-name discovered-schemasQuick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: EventBridge routes events using content-based pattern rules to multiple targets simultaneously, archive and replay allows you to retain and re-process historical events without code changes, and EventBridge Pipes provides managed source-to-target pipelines from streaming sources. Next up we explore Step Functions for orchestrating multi-step serverless workflows.
Frequently asked questions
Is the “EventBridge: Event Bus and Rules” lesson free?
Yes — the full text of “EventBridge: Event Bus and Rules” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “EventBridge: Event Bus and Rules”?
Publish events to a custom EventBridge bus, write event pattern rules to filter and route events to Lambda, SQS, or Step Functions targets. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “EventBridge: Event Bus and Rules” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.