Serverless: EventBridge, the event router
Amazon EventBridge explained: event buses, rules and event patterns, targets, archive and replay, EventBridge Pipes, and EventBridge Scheduler.
Part 4 of the Serverless series.
Amazon EventBridge routes events from producers to consumers that don’t know about each other. A service publishes “an order was placed”; any number of other services can react, and the publisher never changes when a new consumer is added. That decoupling is the heart of event-driven architecture.
Event buses and events
An event bus receives events. Every account has a default bus, which already receives events from AWS services: an EC2 instance changing state, an S3 object being created (when enabled), a CloudFormation stack update. You create custom buses for your application’s own events.
An event is JSON with a standard envelope:
{
"source": "shop.orders",
"detail-type": "OrderPlaced",
"detail": {
"orderId": "o-123",
"customerId": "c-42",
"total": 59.90
}
}
Publish one from code with PutEvents, or from the CLI:
aws events put-events --entries '[{"EventBusName":"shop","Source":"shop.orders","DetailType":"OrderPlaced","Detail":"{\"orderId\":\"o-123\",\"total\":59.9}"}]'
Rules and targets
A rule matches events with an event pattern and sends them to up to five targets (Lambda, SQS, Step Functions, another bus, API destinations for third-party HTTP APIs, and more):
{
"source": ["shop.orders"],
"detail-type": ["OrderPlaced"],
"detail": { "total": [{ "numeric": [">", 100] }] }
}
Patterns support prefix, numeric, “anything-but”, exists and wildcard matching, so filtering happens in EventBridge, not in your code.
Delivery
- Delivery to targets is at least once, so make consumers idempotent.
- Failed deliveries are retried (for up to 24 hours by default), and you can attach a dead-letter queue to each target to catch what still fails.
- Archive and replay keeps events so you can re-send them later; handy for recovering from a bug or back-filling a new consumer.
EventBridge Pipes
Pipes connect one source to one target, with optional filtering, enrichment and transformation, and no glue code. For example, DynamoDB Streams → filter “new orders only” → Step Functions. Sources include SQS, Kinesis, DynamoDB Streams, Amazon MQ and Kafka.
EventBridge Scheduler
Scheduler runs one-off or recurring schedules (cron, rate, or a specific time and time zone) that invoke more than 200 AWS services directly. Use it for “send a reminder in 24 hours” or “close this game at 9pm”, and in place of the older scheduled rules on the default bus.
Hands-on
- Create a custom bus called
shop. - Add a rule matching
OrderPlacedevents with a CloudWatch Logs log group as the target. - Publish a few events with
put-events, varyingtotal, then add the numeric filter above and watch which events arrive in the log group.
When to use EventBridge vs SNS vs SQS
- EventBridge: routing domain events between services and accounts, with content-based filtering. The default for application events.
- SNS: very high-throughput fan-out with low latency, plus SMS, email and mobile push.
- SQS: a buffer between a producer and one consumer, so the consumer can process at its own pace.
They combine well: EventBridge rule → SQS queue → Lambda is a very common production shape.
Next: SQS and SNS: queues and fan-out.
← Series overview