1.1.12 Amazon EventBridge
Use Amazon EventBridge to Implement Event-Driven Patterns
Tổng quan
EventBridge là serverless event bus kết nối applications với data từ nhiều sources.
Core Concepts
| Concept | Mô tả |
|---|
| Event Bus | Channel nhận events (default, custom, partner) |
| Rule | Match events theo pattern và route đến targets |
| Target | Service xử lý event (Lambda, SQS, SNS, Step Functions, etc.) |
| Schema | Cấu trúc của event (Schema Registry) |
Event Pattern Matching
{
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["stopped", "terminated"],
"instance-id": [{"prefix": "i-0"}]
}
}
Filter Types
| Filter | Ví dụ |
|---|
| Exact match | "state": ["running"] |
| Prefix | {"prefix": "prod-"} |
| Suffix | {"suffix": ".png"} |
| Numeric | {"numeric": [">=", 100, "<", 200]} |
| Exists | {"exists": true} |
| Anything-but | {"anything-but": ["test"]} |
Biến đổi event trước khi gửi đến target:
// Input Path
{
"instance": "$.detail.instance-id",
"state": "$.detail.state"
}
// Input Template
"Instance <instance> changed to <state>"
Archive & Replay
- Archive: Lưu trữ events để replay sau
- Replay: Gửi lại archived events vào event bus
- Use case: Testing, debugging, disaster recovery
Scheduling
| Type | Ví dụ |
|---|
| Rate-based | rate(5 minutes) |
| Cron | cron(0 12 * * ? *) — 12:00 UTC daily |
Cross-Account & Cross-Region
- Gửi events giữa các AWS accounts
- Route events đến event bus ở region khác
- Resource-based policy cho phép cross-account access
So sánh với SNS
| Feature | EventBridge | SNS |
|---|
| Filtering | Content-based (rich) | Message attributes |
| Sources | AWS, SaaS, Custom | Custom only |
| Targets | 20+ AWS services | SQS, Lambda, HTTP, Email, SMS |
| Schema | Schema Registry | Không |
| Archive/Replay | Có | Không |
| Throughput | Soft limits | Very high |
Exam Tip: EventBridge = event-driven architecture với rich filtering. Cần schedule = EventBridge Scheduler. Cần SaaS integration = EventBridge partner event bus. Cần archive/replay = EventBridge. Simple pub/sub = SNS.