Explain it simply
Explain it simply
Think of EventBridge as a post office for facts about your system. A service drops off a small JSON letter that says 'this happened': an order was placed, a file landed in S3, an EC2 instance stopped. The sender does not know, and does not care, who reads it.
Rules sit inside the post office and read every letter. Each rule has a pattern, like 'orders over $100 from the web shop', and a list of targets to deliver matching letters to: a Lambda function, an SQS queue, a Step Functions workflow or another event bus. Adding a new reader means adding a rule, not editing the sender.
In AWS Fundamentals you used Lambda with a single trigger. EventBridge is how many services react to the same event without being wired to each other.
Problem → Why → Solution
The problem: point-to-point calls
Imagine an order service that, after checkout, synchronously calls four other services: email, inventory, analytics and loyalty points. The checkout latency is now the sum of all four, and if any one of them is slow or down, the customer sees an error page.
Next month the security team wants a fraud-check service. That means changing, testing and redeploying the order service, even though the order team has nothing to do with fraud checks. Every new consumer makes the producer bigger and more fragile.
import json
import boto3
lambda_client = boto3.client("lambda")
# Every downstream consumer is hard-coded into the producer.
CONSUMERS = ["send-email", "reserve-stock", "track-analytics", "add-points"]
def place_order(order: dict) -> None:
payload = json.dumps(order).encode()
for function_name in CONSUMERS:
# Synchronous: checkout waits for (and fails with) each consumer
lambda_client.invoke(FunctionName=function_name, Payload=payload)
# Adding "fraud-check" means editing and redeploying this service.Why this hurts
The producer must know every consumer by name and inherits their availability. This is tight coupling. In an event-driven design the producer publishes one fact, 'OrderPlaced', once, and is done.
Core concept: buses, rules, patterns, targets
- Event bus
- A router that receives events and evaluates every rule attached to it. An event enters exactly one bus.
There are three kinds of bus. Every account and region has a default bus, and AWS service events (an EC2 instance changing state, a CodePipeline finishing) land there automatically. Custom buses are ones you create for your own application events; one bus per domain keeps permissions and ownership clear. Partner buses receive events from a SaaS partner (ticketing, monitoring, payments) through a partner event source.
Every event shares a fixed envelope: source, detail-type, account, region, time, and a detail field that holds your payload. A rule's event pattern is JSON shaped like that envelope, and two matching rules are enough to remember: different fields are ANDed, values inside an array are ORed. Fields the pattern does not mention are not checked at all.
Beyond exact values there are content filters: prefix (string starts with), numeric (>, >=, <, ranges), anything-but (any value except these) and exists (field present or absent). Matching is type-sensitive: the string "100" in a pattern does not match the number 100.
{
"source": [{ "prefix": "com.shop." }],
"detail-type": ["OrderPlaced"],
"detail": {
"status": [{ "anything-but": ["TEST", "CANCELLED"] }],
"total": [{ "numeric": [">=", 100] }],
"coupon": [{ "exists": false }]
}
}A rule can have up to five targets. Each target can receive the whole event, just one part of it (InputPath), or the output of an input transformer, which extracts fields into variables and places them in a new template. The consumer then sees only the shape it needs and never has to understand the producer's envelope.
Rules work independently of each other. If one event matches ten rules, it is delivered separately to every target of all ten; this is fan-out. A broken rule or a slow target does not affect the other rules. A new consumer team can therefore add its own rule without asking, or waiting for, the producer team.
EVENTBRIDGE ROUTING
-------------------
[order-svc] [payment-svc] producers do not know consumers
| |
v v
+---------------------------------+
| orders-bus (custom) |
| rule: big-orders rule: all |
+-----+----------------+----------+
| match | match
v v
[SQS: fraud-check] [Lambda: email] [archive: orders-archive]
|
+--> retry (backoff) --> DLQ (SQS) when retries run out- Producer publishes one fact
- Bus evaluates every rule
- Matching rule delivers to targets
- Failures retry, then go to DLQ
Delivery is at-least-once and ordering is not guaranteed, so write idempotent consumers.
General pattern: bus, rule, target
aws events create-event-bus --name orders-bus
aws events put-rule --name big-orders --event-bus-name orders-bus \
--event-pattern file://big-orders-pattern.json
# targets.json holds the queue ARN, input transformer, retry policy and DLQ
aws events put-targets --rule big-orders --event-bus-name orders-bus \
--targets file://targets.json
aws events put-events --entries file://sample-events.jsonCreate a bus, attach a rule with a pattern, add targets, then publish a test event. Do not forget --event-bus-name on both put-rule and put-targets; without it the rule is created on the default bus.
Worked example: which orders does the pattern catch?
This script creates the big-orders rule on orders-bus with an SQS queue as its target, publishes six order events and reads which ones reached the queue. Before running it, predict for each event why it should or should not match.
import json
import boto3
events = boto3.client("events", region_name="us-east-1")
sqs = boto3.client("sqs", region_name="us-east-1")
BUS = "orders-bus"
QUEUE_URL = sqs.get_queue_url(QueueName="big-orders")["QueueUrl"]
QUEUE_ARN = sqs.get_queue_attributes(
QueueUrl=QUEUE_URL, AttributeNames=["QueueArn"]
)["Attributes"]["QueueArn"]
# Large, real (non-test) orders from any shop channel, without a coupon
pattern = {
"source": [{"prefix": "com.shop."}],
"detail-type": ["OrderPlaced"],
"detail": {
"status": [{"anything-but": ["TEST", "CANCELLED"]}],
"total": [{"numeric": [">=", 100]}],
"coupon": [{"exists": False}],
},
}
events.put_rule(Name="big-orders", EventBusName=BUS, EventPattern=json.dumps(pattern))
events.put_targets(
Rule="big-orders",
EventBusName=BUS,
Targets=[{"Id": "big-orders-queue", "Arn": QUEUE_ARN}],
)
orders = [
("com.shop.web", {"orderId": "A1", "status": "PAID", "total": 250}),
("com.shop.mobile", {"orderId": "A2", "status": "PAID", "total": 99}),
("com.shop.web", {"orderId": "A3", "status": "TEST", "total": 500}),
("com.shop.web", {"orderId": "A4", "status": "PAID", "total": 300, "coupon": "X"}),
("com.billing", {"orderId": "A5", "status": "PAID", "total": 900}),
("com.shop.mobile", {"orderId": "A6", "status": "PAID", "total": 120.5}),
]
resp = events.put_events(
Entries=[
{
"EventBusName": BUS,
"Source": source,
"DetailType": "OrderPlaced",
"Detail": json.dumps(detail),
}
for source, detail in orders
]
)
print("published:", len(orders), "failed:", resp["FailedEntryCount"])
msgs = sqs.receive_message(QueueUrl=QUEUE_URL, MaxNumberOfMessages=10)
matched = sorted(json.loads(m["Body"])["detail"]["orderId"] for m in msgs["Messages"])
print("delivered to queue:", matched)Not runnable in the browser
This code runs against a real AWS account, so it cannot run in the browser playground. Try it in your own terminal or in AWS CloudShell.
Code breakdown
- Pattern
"source": [{"prefix": "com.shop."}]Both com.shop.web and com.shop.mobile match. com.billing (A5) fails however large its total, because one failed field fails the whole event (AND).
- Numeric
"total": [{"numeric": [">=", 100]}]A2 (99) is rejected; A6 (120.5) matches even though it is a decimal. Numeric matching only works on JSON numbers.
- anything-but / exists
"coupon": [{"exists": False}]A3 has status TEST, so anything-but rejects it. A4 carries a coupon field, so exists: false rejects it. It is False in Python and becomes false in the JSON.
- put_events
FailedEntryCount only says whether the bus accepted each event, not whether a target received it. Delivery failures show up in CloudWatch metrics and the DLQ.
published: 6 failed: 0
delivered to queue: ['A1', 'A6']- Bus accepts PutEvents
- Event matched against rules
- Input transformer applied
- Target invoked
Target succeeds
Done (at-least-once)
Retries exhausted
Sent to DLQ
Delivery: retry policy, DLQ and input transformer
When a target is throttled or briefly unavailable, EventBridge retries with exponential backoff and jitter. By default it keeps trying for up to 24 hours and 185 attempts, and after that, without a DLQ, the event is silently dropped. Lower MaximumRetryAttempts and MaximumEventAgeInSeconds per target and attach an SQS DLQ so failed events can be inspected and redriven later.
[
{
"Id": "fraud-check-queue",
"Arn": "arn:aws:sqs:us-east-1:111122223333:fraud-check",
"InputTransformer": {
"InputPathsMap": {
"orderId": "$.detail.orderId",
"total": "$.detail.total"
},
"InputTemplate": "{\"order\": \"<orderId>\", \"amount\": <total>}"
},
"RetryPolicy": {
"MaximumRetryAttempts": 8,
"MaximumEventAgeInSeconds": 3600
},
"DeadLetterConfig": {
"Arn": "arn:aws:sqs:us-east-1:111122223333:fraud-check-dlq"
}
}
]The DLQ needs its own permission
EventBridge can only write to the DLQ if the queue's resource policy allows events.amazonaws.com to call sqs:SendMessage. Without it, the event is lost instead of landing in the DLQ.
Archive, replay and the schema registry
An archive stores events that pass through a bus (optionally filtered by a pattern) for a retention period you choose. After fixing a bug in a consumer, you can replay a time window of events back onto the bus. Replayed events carry a replay-name field, so rules with side effects, such as sending emails, can skip them with "replay-name": [{"exists": false}].
The schema registry is a catalogue of event shapes. It already contains schemas for AWS service events, and if you enable schema discovery on a bus it infers schemas for your custom events too. You can download code bindings for languages such as Python, TypeScript and Java from those schemas, so consumer teams stop guessing at payload shapes.
BUS_ARN=$(aws events describe-event-bus --name orders-bus --query Arn --output text)
aws events create-archive --archive-name orders-archive \
--event-source-arn "$BUS_ARN" --retention-days 30
ARCHIVE_ARN=$(aws events describe-archive --archive-name orders-archive \
--query ArchiveArn --output text)
# Re-deliver one hour of events to the same bus after a consumer fix
aws events start-replay --replay-name fix-fraud-check-2026-03-01 \
--event-source-arn "$ARCHIVE_ARN" \
--event-start-time 2026-03-01T09:00:00Z --event-end-time 2026-03-01T10:00:00Z \
--destination Arn="$BUS_ARN"
aws events describe-replay --replay-name fix-fraud-check-2026-03-01Pipes, Scheduler and cross-account delivery
EventBridge Pipes is for point-to-point integration rather than fan-out: one source (SQS, Kinesis, DynamoDB Streams, Amazon MQ, Kafka and others), an optional filter, an optional enrichment step (Lambda, Step Functions Express, API Gateway and others), and one target. It replaces 'glue' Lambdas whose only job is to read a stream and forward records.
EventBridge Scheduler is a separate service from scheduled rules on a bus. It supports at() for one-off runs, rate() and cron() expressions with time zones, and is designed for very large numbers of schedules, such as one reminder per user. A flexible time window spreads invocations across a window so they do not hit the target all at once.
For cross-account delivery, a rule in the sending account targets the receiving account's event bus ARN, using an IAM role that is allowed to call events:PutEvents. The receiving bus's resource policy must also allow the sender; a common approach is an aws:PrincipalOrgID condition that admits the whole organization instead of listing accounts one by one.
# One reminder per invoice, delivered to an SQS queue at a fixed local time
aws scheduler create-schedule --name invoice-1042-reminder \
--schedule-expression "at(2026-03-15T09:00:00)" \
--schedule-expression-timezone "Asia/Yangon" \
--flexible-time-window Mode=OFF \
--target Arn=arn:aws:sqs:us-east-1:111122223333:reminders,RoleArn=$SCHEDULER_ROLE_ARN
# Stream new orders from a DynamoDB table straight to the orders bus
aws pipes create-pipe --name orders-stream-to-bus \
--source "$ORDERS_STREAM_ARN" \
--source-parameters '{"DynamoDBStreamParameters": {"StartingPosition": "LATEST"}}' \
--target "$BUS_ARN" \
--role-arn "$PIPE_ROLE_ARN"In production
In production
In larger organizations each domain (orders, payments, shipping) owns its own custom bus and forwards to a shared 'event backbone' account through cross-account rules. Events are treated as a contract, like an API: teams version them in the detail-type (OrderPlaced.v2) or a version field in the detail, and only add fields rather than removing old ones abruptly.
- CloudWatch alarms on FailedInvocations and on invocations sent to the DLQ for every rule.
- Every consumer uses the event id as an idempotency key so a duplicate delivery is not processed twice.
- Slow consumers sit behind an SQS queue instead of being a direct Lambda target, which adds buffering and batching.
- Archives on every production bus, so data can be backfilled with a replay after an incident.
EventBridge adds more latency than a direct call (it can reach the hundreds of milliseconds), so teams keep it out of the synchronous path where a user waits for an answer. Checkout stores the order and responds; everything else happens asynchronously from the event.
Common mistakes
Common mistakes
Mistake 1: a rule that triggers itself
A rule catches S3 'Object Created' events and invokes a Lambda, which writes a thumbnail back into the same bucket. That write emits a new event, which matches the rule again. The result is an endless loop and a large bill. Write output to a separate prefix or bucket that the pattern excludes, or reject your own source with anything-but.
Mistake 2: assuming exactly-once and ordering
EventBridge delivers at least once and does not guarantee order. 'OrderShipped' can arrive before 'OrderPaid', and the same event can arrive twice. Consumers should deduplicate on the event id and compare state using a timestamp or version. If you truly need ordering, consider SQS FIFO or Kinesis instead.
Mistake 3: trusting default retries without a DLQ
If a target's permissions are wrong (for example, a missing Lambda resource policy), retries never succeed, and without a DLQ the events quietly disappear after 24 hours. Mixing the string "100" and the number 100 in a pattern is another silent failure: nothing matches and nothing errors.
Best practices
Best practices
- Put facts (things that happened) in events, not commands ('do this').
- Include enough data for consumers to act, but never sensitive data such as card numbers.
- Code-review rule patterns and test them with sample events.
- Give every target an explicit retry policy and a DLQ.
💰 Cost & Cleanup
AWS service events arriving on the default bus are free. Publishing custom events is billed per million events (roughly $1 per million in us-east-1; check the pricing page). Archives are billed for storage and processing, replays for the events they re-send, and schema discovery for events it ingests. Pipes and Scheduler have their own request charges. This lab sends a handful of events and costs very little, but leftover archives and schedules keep costing money, so delete everything with the commands below.
Clean up when you are done
aws events remove-targets --rule big-orders --event-bus-name orders-bus \
--ids fraud-check-queue
aws events delete-rule --name big-orders --event-bus-name orders-bus
aws events delete-archive --archive-name orders-archive
aws scheduler delete-schedule --name invoice-1042-reminder
aws pipes delete-pipe --name orders-stream-to-bus
aws events delete-event-bus --name orders-bus
aws sqs delete-queue --queue-url "$FRAUD_QUEUE_URL"
aws sqs delete-queue --queue-url "$FRAUD_DLQ_URL"Mini challenge
Mini challenge: a cancelled-orders rule
Write the event pattern for a new rule on orders-bus that feeds the refund team's queue.
- Only OrderPlaced events from sources starting with com.shop.
- status must be CANCELLED or REFUNDED
- Replayed events must be excluded
Expected: A normal event with status CANCELLED matches; the same event delivered by a replay does not.
Show hint
Values in one array are ORed. Replayed events carry a top-level replay-name field.
Show solution
{
"source": [{ "prefix": "com.shop." }],
"detail-type": ["OrderPlaced"],
"replay-name": [{ "exists": false }],
"detail": {
"status": ["CANCELLED", "REFUNDED"]
}
}Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- Default bus for AWS service events, custom buses for your app events, partner buses for SaaS events.
- In a pattern, fields are ANDed, array values are ORed, and matching is type-sensitive.
- Give every target a retry policy and a DLQ, and write idempotent consumers.
- Archive/replay is for recovery, Pipes for point-to-point flows, Scheduler for time-based invocations.
Amazon EventBridge User Guide — AWS Documentation
Amazon EventBridge event patterns — AWS Documentation
Amazon EventBridge Scheduler User Guide — AWS Documentation