AWS EventBridge
Amazon EventBridge is a serverless event router. It receives events from AWS services, your own applications, and software partners. Rules then send each event to the right target, such as a Lambda function, a queue, or a workflow.
Think of a post office sorting room. Letters arrive from everywhere. Workers read each address and drop every letter into the correct delivery bag. EventBridge reads each event and delivers it to every interested target.
What Is an Event
An event is a small message that says something happened. Examples include a new file landing in S3, an EC2 instance stopping, or a customer placing an order. Events arrive as JSON documents.
{
"source": "myapp.orders",
"detail-type": "OrderPlaced",
"detail": {
"orderId": "A1001",
"amount": 250,
"country": "IN"
}
}
Core Building Blocks
- Event bus: the pipe that receives events. Every account has a default bus for AWS service events.
- Rule: a filter that matches events and chooses targets.
- Target: the service that reacts, such as Lambda, SQS, SNS, Step Functions, or an API endpoint.
- Schema registry: a catalog that describes event structures for developers.
How It Flows
Event Sources Event Bus Targets
+--------------+ +-------------+ +-------------+
| AWS services |--------->| |--+--->| Lambda |
| Your app |--------->| Rules | | +-------------+
| SaaS partner |--------->| (filters) | +--->| SQS Queue |
+--------------+ +-------------+ | +-------------+
+--->| Step Func. |
+-------------+
Event Patterns
A pattern tells a rule which events to catch. The pattern below matches only orders above 100 from India.
{
"source": ["myapp.orders"],
"detail-type": ["OrderPlaced"],
"detail": {
"country": ["IN"],
"amount": [{ "numeric": [">", 100] }]
}
}
Events that fail the pattern never reach the target, so downstream code stays simple.
Scheduled Rules
EventBridge also triggers targets on a schedule. A cron expression runs a Lambda function every night at 2 AM to clean temporary files. A rate expression such as every five minutes handles regular checks. EventBridge Scheduler supports one-time and recurring schedules at large scale.
Example: Order Processing
An online store emits an OrderPlaced event. Three independent systems react without knowing about each other.
OrderPlaced event
|
Event Bus
/ | \
Email Lambda Inventory Analytics
(send receipt) Queue Firehose
Adding a fourth system, such as a loyalty points service, means adding one rule. Existing code stays untouched. The design is called loosely coupled architecture.
EventBridge, SNS, and SQS Compared
- SNS pushes one message to many subscribers with simple topic filtering.
- SQS holds messages in a queue until a consumer pulls them.
- EventBridge filters events by content, connects to many AWS services and SaaS partners, and supports schedules.
Many designs combine them. EventBridge routes the event, and an SQS queue buffers work for a slow consumer.
Reliability Features
- Retry policies resend an event when a target fails.
- Dead-letter queues store events that never reach their target.
- Archive and replay save past events and resend them to test fixes.
Cross-Account and Partner Events
A bus can receive events from other AWS accounts when a resource policy allows it. Central security teams use this ability to collect events from every account in one place. Partner event sources let supported SaaS providers send events directly to your bus.
Practice Steps
- Create a Lambda function that logs the event it receives.
- Open EventBridge and create a rule on the default bus.
- Choose an AWS service event, such as EC2 instance state change.
- Set the Lambda function as the target.
- Stop a test instance and read the Lambda logs in CloudWatch.
Best Practices
- Keep event names clear and consistent.
- Version event structures when they change.
- Attach a dead-letter queue to every important target.
- Avoid putting sensitive personal data inside events.
