Amazon EventBridge

Formerly CloudWatch Events — same service, bigger name. It is the reaction layer of an AWS account: something happens (or a clock ticks), a rule matches it, and one to five targets get invoked. If a question says "when X happens, automatically do Y" and X isn't an S3 or SQS event feeding a single consumer, the answer is almost always EventBridge.

Tên cũ là CloudWatch Events — vẫn service đó, chỉ đổi tên rộng hơn. Đây là lớp phản ứng của một account AWS: có việc gì đó xảy ra (hoặc đồng hồ điểm giờ), một rule khớp, và một tới năm target được gọi. Câu hỏi dạng "khi X xảy ra thì tự động làm Y" — mà X không phải event S3/SQS đổ vào đúng một consumer — gần như luôn là EventBridge.

Reach for itNên dùng

  • Serverless cron — "run this every hour" without an EC2 box running crontabCron serverless — "chạy mỗi giờ" mà không cần một EC2 chạy crontab
  • React to an AWS control-plane change: instance started, build failed, root user signed inPhản ứng với thay đổi control-plane của AWS: instance start, build fail, root user đăng nhập
  • The fastest way to react to a CloudTrail API callCách nhanh nhất để phản ứng với một API call trong CloudTrail
  • One event, several different kinds of target (Lambda + Step Functions + SSM + queue)Một event, nhiều loại target khác nhau (Lambda + Step Functions + SSM + queue)
  • Central audit/automation bus for an OrganizationBus trung tâm cho audit/automation của cả Organization

Not the right toolKhông hợp

  • High-throughput streaming with ordering and replay by position → Kinesis / MSKStreaming throughput cao, có thứ tự và replay theo vị trí → Kinesis / MSK
  • Fan-out of your own high-volume messages to many queues → SNS → SQS is cheaper and simplerFan-out message của chính bạn với lượng lớn ra nhiều queue → SNS → SQS rẻ và đơn giản hơn
  • A worker that needs a durable backlog it polls at its own pace → SQSWorker cần backlog bền, tự poll theo nhịp của nó → SQS
  • Multi-step workflow with branching, retries and human approval → Step Functions (EventBridge just starts it)Workflow nhiều bước có rẽ nhánh, retry, chờ người duyệt → Step Functions (EventBridge chỉ khởi động nó)

1 · Two ways a rule fires1 · Hai kiểu kích hoạt rule

Everything EventBridge does starts as one of these. Schedule = a clock triggers it, nothing happened in the account. Event pattern = something happened, and the pattern decides whether this particular thing is interesting. Mọi thứ EventBridge làm đều bắt đầu từ một trong hai. Schedule = đồng hồ kích hoạt, chẳng có gì xảy ra trong account. Event pattern = có việc xảy ra, và pattern quyết định việc đó có đáng quan tâm không.

Two trigger types: a schedule rule invokes a Lambda every hour, and an event-pattern rule matching an IAM root user sign-in publishes to an SNS topic that sends email schedule — the clock is the trigger every 1 hour cron(0 * * * ? *) EventBridge rule Lambda function runs the script event pattern — something happened, does it match? IAM root user sign-in event on the default bus EventBridge rule pattern matches → keep SNS topic email notification a rule that matches nothing simply never fires — no error, no cost

Same rule object, two Trigger choices. Recognise the shape: clock → target is the serverless-cron answer; event → target is the react-to-something answer.

Cùng một đối tượng rule, hai lựa chọn Trigger. Nhớ hình dạng: đồng hồ → target là đáp án cron serverless; event → target là đáp án phản ứng theo sự kiện.

  • Schedule: cron jobs (scheduled scripts) — e.g. "schedule every hour" → trigger a script on a Lambda function. This is the standard serverless CRON job.Schedule: cron job (script chạy theo lịch) — vd "mỗi giờ một lần" → chạy script trên Lambda. Đây là cron job serverless tiêu chuẩn.
  • Event pattern: event rules to react to a service doing something — e.g. an IAM root user sign-in event → SNS topic with email notification.Event pattern: rule phản ứng khi một service làm gì đó — vd event root user đăng nhập → SNS topic gửi email.
  • An event pattern is just JSON listing the values you accept — {"source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": {"state": ["stopped"]}}. A field you omit matches anything; a field you list must match one of the values.Event pattern chỉ là JSON liệt kê giá trị bạn chấp nhận — {"source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": {"state": ["stopped"]}}. Field không ghi thì khớp mọi thứ; field có ghi thì phải khớp một trong các giá trị.
  • Both kinds end the same way: trigger Lambda functions, send SQS/SNS messages… — the target list is what makes it useful.Cả hai kiểu đều kết thúc giống nhau: gọi Lambda, gửi message SQS/SNS… — danh sách target mới là thứ làm nó hữu dụng.
cron vs ratecron vs rate rate(1 hour) means "every hour from now". cron(0 9 ? * MON-FRI *) means "09:00 on weekdays" — six fields, and unlike Unix cron you must supply a ? in either day-of-month or day-of-week because only one of the two can be specified. rate(1 hour) nghĩa là "mỗi giờ tính từ bây giờ". cron(0 9 ? * MON-FRI *) nghĩa là "09:00 các ngày trong tuần" — sáu trường, và khác Unix cron, phải đặt ? ở day-of-month hoặc day-of-week vì chỉ một trong hai được chỉ định.

2 · Rules: source → filter → targets2 · Rule: source → filter → target

The whole service in one picture. Sources push JSON onto a bus, the rule's pattern filters it, and the matching event — the same JSON document — is delivered to every target on the rule. Toàn bộ service gói trong một hình. Source đẩy JSON lên bus, pattern của rule lọc lại, và event khớp — đúng tài liệu JSON đó — được giao tới mọi target của rule.

Example sources such as EC2, CodeBuild, S3, Trusted Advisor, CloudTrail and schedules flow through an optional filter into EventBridge, which delivers the JSON event to targets grouped as compute, integration, orchestration and maintenance Example sources EC2 instance ex: start instance CodeBuild ex: failed build S3 event ex: upload object Trusted Advisor ex: new finding CloudTrail any API call schedule or cron filter Amazon EventBridge bus + rule pattern { "version": "0", "id": "6a7e8feb-b491", "detail-type": "EC2 Instance State-change", … } the event, as JSON Example targets compute Lambda · AWS Batch · ECS task integration SQS · SNS · Kinesis Data Streams orchestration Step Functions · CodePipeline · CodeBuild maintenance SSM · EC2 actions up to 5 targets per rule · each gets the same JSON · failures retry for 24h, then DLQ

The target column is the point: one event can start a workflow, queue a message and patch a fleet at the same time. Nothing else in AWS wires that many different kinds of service together in one hop.

Cột target mới là điểm chính: một event có thể đồng thời khởi động workflow, đẩy message vào queue và vá cả fleet. Không service nào khác của AWS nối được nhiều loại service khác nhau như vậy chỉ trong một bước.

  • Sources include EC2 instance state changes, CodeBuild results, S3 events, Trusted Advisor findings, any CloudTrail API call, and schedules. Filtering the events is optional — a rule with no pattern beyond the source takes everything from it.Source gồm thay đổi trạng thái EC2, kết quả CodeBuild, S3 event, finding của Trusted Advisor, mọi API call trong CloudTrail, và schedule. Lọc event là tuỳ chọn — rule không có pattern nào ngoài source sẽ lấy tất cả.
  • The event handed to the target is a JSON document with version, id, detail-type, source, account, time, region, resources and a service-specific detail object.Event giao cho target là một tài liệu JSON gồm version, id, detail-type, source, account, time, region, resources và object detail riêng theo từng service.
  • Up to 5 targets per rule, and they can be different services. Need more than five? Point the rule at SNS and fan out, or add a second rule with the same pattern.Tối đa 5 target mỗi rule, và có thể là các service khác nhau. Cần nhiều hơn năm? Trỏ rule vào SNS rồi fan-out, hoặc thêm rule thứ hai cùng pattern.
  • Delivery is retried with backoff for up to 24 hours; what still fails goes to the target's dead-letter queue (an SQS queue you attach per target) — otherwise it is dropped silently.Delivery được retry có backoff tới 24 giờ; cái vẫn fail sẽ vào dead-letter queue của target (một queue SQS bạn gắn cho từng target) — không có thì nó bị bỏ im lặng.
  • Input transformer: reshape the JSON before it reaches the target, so a Lambda or an SSM document receives the two fields it wants instead of the whole event.Input transformer: nắn lại JSON trước khi tới target, để Lambda hay SSM document nhận đúng hai field nó cần thay vì cả event.
Application: react to a CloudTrail API call as fast as possibleỨng dụng: phản ứng nhanh nhất với một API call trong CloudTrail Three ways to consume CloudTrail, and the exam wants the fastest. EventBridge can be triggered for any API call — the fastest, most reactive way. CloudTrail → CloudWatch Logs streams events and lets you metric-filter them. CloudTrail → S3 delivers every 5 minutes and is for integrity validation, cross-account delivery and long-term storage. Overall CloudTrail may take up to 15 minutes to deliver events. Ba cách tiêu thụ CloudTrail, và đề luôn hỏi cách nhanh nhất. EventBridge kích hoạt được với bất kỳ API call nào — nhanh và phản ứng tức thì nhất. CloudTrail → CloudWatch Logs stream event và cho phép metric filter. CloudTrail → S3 giao mỗi 5 phút, dùng cho kiểm tra tính toàn vẹn, giao cross-account và lưu trữ dài hạn. Nhìn chung CloudTrail có thể mất tới 15 phút để giao event.

3 · Event buses3 · Event bus

A bus is the pipe events land on; rules are attached to a bus, not to the account. Which bus an event arrives on tells you who produced it — AWS, a SaaS vendor, or your own code. Một bus là cái ống mà event rơi vào; rule gắn vào bus chứ không gắn vào account. Event đến bằng bus nào cho biết ai sinh ra nó — AWS, một hãng SaaS, hay code của chính bạn.

Each kind of producer feeds its own bus — AWS services always land on the default bus, each SaaS partner gets a partner bus, and your own code names the bus in PutEvents. Rules are attached to one bus, and each rule invokes its own targets. producers AWS services EC2 · S3 · CloudTrail SaaS partners Zendesk · Datadog · Auth0 your own apps PutEvents(EventBusName) always always you pick the bus default event bus one per account, per region you never create it partner event bus one per SaaS event source they push, you subscribe custom event bus as many as you want $1 per million events rule · pattern aws.ec2 · state: stopped rule · pattern zendesk · ticket.created rule · pattern orders · order.placed Lambda · SSM SNS topic SQS · Step Functions every bus can archive — keep events (all or filtered) indefinitely or for N days replay — push archived events back through that bus, later a rule sees one bus only — a rule on the custom bus never sees default-bus events your apps can target the default bus too: omit EventBusName and that is where it goes

The three columns never merge. Which bus an event is on is decided by who produced it — AWS picks for you, the partner picks for you, and your code picks with EventBusName. Rules, archives and policies all hang off one specific bus.

Ba cột không bao giờ nhập lại. Event nằm ở bus nào là do ai sinh ra nó quyết định — AWS chọn sẵn, partner chọn sẵn, còn code của bạn chọn bằng EventBusName. Rule, archive và policy đều móc vào đúng một bus cụ thể.

  • Producers do not share one bus. AWS service events always land on the default bus — you cannot point them at a custom one. Each SaaS integration gets its own partner bus. Your code chooses with PutEvents(EventBusName), defaulting to the default bus if you omit it.Producer không dùng chung một bus. Event của service AWS luôn rơi vào default bus — không trỏ sang custom bus được. Mỗi tích hợp SaaS có partner bus riêng. Code của bạn chọn bằng PutEvents(EventBusName), bỏ trống thì vào default bus.
  • Buses are isolated from each other — a rule on one bus never sees another bus's events. To join them, add a rule whose target is the other bus.Các bus tách biệt nhau — rule trên bus này không thấy event của bus kia. Muốn nối lại, tạo rule có target chính là bus kia.
  • A rule belongs to exactly one bus — and a schedule rule can only be created on the default bus. A custom bus takes event patterns only; for schedules at scale, that is what EventBridge Scheduler is for.Mỗi rule thuộc đúng một bus — và rule kiểu schedule chỉ tạo được trên default bus. Custom bus chỉ nhận event pattern; cần schedule quy mô lớn thì đó là việc của EventBridge Scheduler.
  • Event buses can be accessed by other AWS accounts using resource-based policies — see the next section.Bus có thể cho account AWS khác truy cập bằng resource-based policy — xem phần kế tiếp.
  • You can archive events (all, or a filtered subset) sent to an event bus, indefinitely or for a set period, and then replay archived events.Có thể archive event (toàn bộ hoặc một tập đã lọc) gửi vào bus, vĩnh viễn hoặc trong khoảng thời gian đặt trước, rồi replay event đã archive.
  • A replay re-injects the archived events; targets see them again. Use a separate rule for replays if reprocessing must not repeat the original side effects.Replay bơm lại event đã archive; target nhận lại chúng. Dùng rule riêng cho replay nếu việc xử lý lại không được lặp lại side effect ban đầu.

4 · Resource-based policy: one bus for the whole Organization4 · Resource-based policy: một bus cho cả Organization

A resource-based policy is a permission document attached to the resource instead of to the caller — like an S3 bucket policy. On an event bus it answers one question: which accounts and regions may call PutEvents on me? Resource-based policy là tài liệu phân quyền gắn trên tài nguyên thay vì trên người gọi — giống bucket policy của S3. Trên event bus nó trả lời đúng một câu: account và region nào được phép gọi PutEvents vào tôi?

A resource-based policy on the central event bus in one account allows a Lambda function in another account to call PutEvents, which is how events from an entire Organization are aggregated into a single account policy attached to the bus { "Effect": "Allow", "Action": "events:PutEvents", "Principal": {"AWS": "111122223333"}, "Resource": "arn:aws:events: …:event-bus/central-event-bus" } account 123456789012 EventBridge bus central-event-bus account 111122223333 Lambda function PutEvents same mechanism, cross-region — allow or deny events from another account or region use case: aggregate all events from your AWS Organization into a single account or region each member account keeps a rule that forwards its events to the central bus

Two hops, always: a rule in the member account whose target is the central bus, and a policy on the central bus that trusts the member account.

Luôn là hai bước: một rule trong account thành viên có target là bus trung tâm, và một policy trên bus trung tâm tin tưởng account thành viên đó.

  • Manage permissions for a specific event bus. Example: allow/deny events from another AWS account or AWS region.Quản lý quyền cho một event bus cụ thể. Ví dụ: cho phép/chặn event từ account hoặc region AWS khác.
  • Use case: aggregate all events from your AWS Organization in a single AWS account or AWS region — the standard central-audit answer.Use case: gom mọi event của cả AWS Organization về một account hoặc một region — đáp án chuẩn cho bài toán audit tập trung.
  • The Principal can be an account ID or an aws:PrincipalOrgID condition, so new accounts joining the Organization work without editing the policy.Principal có thể là account ID hoặc điều kiện aws:PrincipalOrgID, để account mới gia nhập Organization chạy được mà không phải sửa policy.
  • Forwarding needs an IAM role on the sending rule as well — the policy on the bus grants access, the role lets the rule use it.Việc forward còn cần IAM role trên rule gửi đi — policy trên bus cấp quyền, role cho phép rule dùng quyền đó.

5 · Schema Registry5 · Schema Registry

A schema is the description of an event's shape — which fields exist and of what type. EventBridge can watch a bus, infer that shape automatically, and hand your IDE typed classes for it, so you stop guessing what detail contains. Schema là mô tả cấu trúc của event — có field nào, kiểu gì. EventBridge quan sát bus, tự suy ra cấu trúc đó, và sinh class có kiểu cho IDE, để bạn khỏi đoán trong detail có gì.

DiscoverDiscover EventBridge analyzes the events in your bus and infers the schema — nothing to write by handEventBridge phân tích event trên bus và tự suy ra schema — không phải viết tay
Code bindingsCode binding Generate code for your application, so it knows in advance how data is structured in the bus (Java, Python, TypeScript…)Sinh code cho ứng dụng, để nó biết trước dữ liệu trên bus có cấu trúc thế nào (Java, Python, TypeScript…)
VersionedCó version Schemas can be versioned — a producer adding a field creates version 2, old consumers keep compiling against version 1Schema đánh version được — producer thêm field thì sinh version 2, consumer cũ vẫn build theo version 1
  • AWS service events are already in the registry under aws.events — e.g. aws.codepipeline@CodePipelineActionExecutionStateChange. Your own events get discovered once you enable discovery on the bus.Event của service AWS đã có sẵn trong registry dưới aws.events — vd aws.codepipeline@CodePipelineActionExecutionStateChange. Event của bạn được phát hiện khi bật discovery trên bus.
  • Schemas are stored as OpenAPI 3 / JSON Schema, which is why the generated bindings look like API client models.Schema lưu dạng OpenAPI 3 / JSON Schema, nên code binding sinh ra trông giống model của API client.
  • Registry ≠ validation: it documents and generates code. It does not reject an event that fails to match.Registry ≠ validation: nó tài liệu hoá và sinh code. Nó không từ chối event không khớp.

6 · Where it shows up elsewhere6 · Nơi nó xuất hiện ở chỗ khác

EventBridge is rarely the subject of a question — it is usually the connective tissue in someone else's diagram. These are the recurring ones. EventBridge hiếm khi là chủ đề chính của câu hỏi — nó thường là mô liên kết trong sơ đồ của service khác. Đây là những chỗ hay gặp lại.

  • Running jobs: "provision an EC2 instance for long-running CRON jobs" is strategy 1; EventBridge + Lambda is strategy 2, and EventBridge is also what kicks off the Batch, Fargate and EMR strategies on a schedule.Chạy job: "dựng một EC2 cho CRON job chạy dài" là chiến lược 1; EventBridge + Lambda là chiến lược 2, và EventBridge cũng là thứ khởi động các chiến lược Batch, Fargate, EMR theo lịch.
  • CloudWatch Alarms integrate with EventBridge alongside EC2 actions, Auto Scaling and SNS — that is how an alarm reaches Step Functions, Kinesis or Lambda.CloudWatch Alarm tích hợp với EventBridge bên cạnh EC2 action, Auto Scaling và SNS — đó là cách một alarm chạm tới Step Functions, Kinesis hay Lambda.
  • AWS Health: use EventBridge to react to changes for AWS Health events in your account — e.g. email when your EC2 instances are scheduled for updates. It cannot return public events from the Service Health Dashboard.AWS Health: dùng EventBridge để phản ứng với thay đổi của AWS Health event trong account — vd gửi email khi EC2 của bạn bị lên lịch cập nhật. Nó không lấy được event công khai từ Service Health Dashboard.
  • Trusted Advisor can tell you a bucket is public but cannot check whether individual objects inside it are public — use EventBridge / S3 Events or AWS Config rules instead.Trusted Advisor báo được bucket là public nhưng không kiểm tra được từng object bên trong có public hay không — dùng EventBridge / S3 Events hoặc AWS Config rule thay thế.
  • Lambda async invocation sources are S3, SNS, EventBridge…; Lambda retries 3 times, so make the processing idempotent and attach a DLQ (SNS or SQS).Nguồn gọi Lambda bất đồng bộ là S3, SNS, EventBridge…; Lambda retry 3 lần, nên xử lý phải idempotent và gắn DLQ (SNS hoặc SQS).
Two newer relatives worth recognisingHai người anh em mới, nên nhận mặt EventBridge Scheduler is the schedule half split out into its own service: one-time or recurring, time zones and daylight saving, flexible time windows, and millions of schedules — no bus or rule involved. EventBridge Pipes is point-to-point instead of pub/sub: one source (SQS, Kinesis, DynamoDB Streams, MSK, MQ) → optional filter → optional enrichment → one target, replacing the Lambda you would otherwise write just to move data. EventBridge Scheduler là phần schedule được tách ra thành service riêng: chạy một lần hoặc lặp lại, có múi giờ và daylight saving, cửa sổ thời gian linh hoạt, và hàng triệu schedule — không cần bus hay rule. EventBridge Pipes là point-to-point thay vì pub/sub: một source (SQS, Kinesis, DynamoDB Streams, MSK, MQ) → filter tuỳ chọn → enrichment tuỳ chọn → một target, thay cho con Lambda mà bạn phải viết chỉ để chuyển dữ liệu.

Exam reflexesPhản xạ khi thi

  • "Run a script every hour without managing a server" → EventBridge schedule → Lambda. Not an EC2 with crontab."Chạy script mỗi giờ mà không quản server" → EventBridge schedule → Lambda. Không phải EC2 chạy crontab.
  • "React to an API call as fast as possible" → EventBridge on the CloudTrail event, not the S3 delivery (5 minutes) and not the log stream."Phản ứng với một API call nhanh nhất có thể" → EventBridge bắt event CloudTrail, không phải delivery vào S3 (5 phút), cũng không phải log stream.
  • "Alert when the root user signs in" → event pattern rule → SNS email. The canonical example."Báo động khi root user đăng nhập" → rule theo event pattern → SNS email. Ví dụ kinh điển.
  • "Collect events from every account in the Organization into one place" → forwarding rules + resource-based policy on a central bus."Gom event từ mọi account trong Organization về một chỗ" → rule forward + resource-based policy trên bus trung tâm.
  • "Reprocess the events we dropped while the consumer was broken" → archive + replay. Kinesis-style retention is not the only answer."Xử lý lại đống event bị rơi lúc consumer hỏng" → archive + replay. Không phải chỉ có retention kiểu Kinesis.
  • "Events are silently disappearing" → no DLQ on the target, or the rule's IAM role can't invoke it. Deliveries retry for 24 hours first."Event tự nhiên biến mất" → chưa gắn DLQ cho target, hoặc IAM role của rule không gọi được target. Trước đó delivery vẫn retry trong 24 giờ.
  • "Ingest events from Datadog / Zendesk / Auth0" → partner event bus, not a webhook into API Gateway."Nhận event từ Datadog / Zendesk / Auth0" → partner event bus, không phải webhook vào API Gateway.
  • "Six things must happen on one event" → a rule caps at 5 targets: add a second rule, or fan out through SNS."Một event phải kích hoạt sáu việc" → mỗi rule tối đa 5 target: thêm rule thứ hai, hoặc fan-out qua SNS.