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

ConceptMô tả
Event BusChannel nhận events (default, custom, partner)
RuleMatch events theo pattern và route đến targets
TargetService xử lý event (Lambda, SQS, SNS, Step Functions, etc.)
SchemaCấ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

FilterVí dụ
Exact match"state": ["running"]
Prefix{"prefix": "prod-"}
Suffix{"suffix": ".png"}
Numeric{"numeric": [">=", 100, "<", 200]}
Exists{"exists": true}
Anything-but{"anything-but": ["test"]}

Input Transformers

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

TypeVí dụ
Rate-basedrate(5 minutes)
Croncron(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

FeatureEventBridgeSNS
FilteringContent-based (rich)Message attributes
SourcesAWS, SaaS, CustomCustom only
Targets20+ AWS servicesSQS, Lambda, HTTP, Email, SMS
SchemaSchema RegistryKhông
Archive/ReplayKhông
ThroughputSoft limitsVery 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.