Sub topic 1
Routing events with Amazon EventBridge
Prerequisites
You should understand AWS accounts and regions, JSON, basic IAM roles and policies, and at least one AWS service such as Lambda or SQS.
Why route events: producers, routers, and consumers
Event-driven architecture lets one component announce that something happened without calling every component that might care. A producer creates an event. EventBridge is the router: it receives events, evaluates rules, and sends matching events to consumers, also called targets.
This separates components. An order service can publish OrderPlaced once. Independent consumers can update inventory, send email, or start a workflow. Adding a consumer usually requires a new rule rather than changing the producer.
Anatomy of an EventBridge event
An event has an envelope and a detail object. The envelope identifies where the event came from and what kind of event it is. The detail object contains application data.
Common fields include:
source: a producer identifier, such ascom.example.orders.detail-type: the event name, such asOrderPlaced.detail: JSON data specific to the event.idandtime: fields commonly added by EventBridge.
Rules can match envelope fields and values inside detail. Keep event names and detail fields stable because consumers depend on them.
Event buses: default, custom, and partner
An event bus is the endpoint that receives events.
- The default bus receives events from many AWS services in your account.
- A custom bus is useful for application events, such as order or payment events.
- A partner bus receives events from an approved SaaS integration.
Use a custom bus to separate application traffic from AWS service events and to apply focused access policies.
Publishing custom events with PutEvents
Create a bus, then publish an event with the AWS CLI:
aws events create-event-bus --name orders-bus
aws events put-events --entries '[{"Source":"com.example.orders","DetailType":"OrderPlaced","Detail":"{\"orderId\":\"1001\",\"amount\":250,\"status\":\"new\"}","EventBusName":"orders-bus"}]'Detail must be a JSON document encoded as a string. PutEvents can accept multiple entries. Check FailedEntryCount; a successful API call does not guarantee that every entry was accepted.
Exercise
Which component should change when a new consumer needs matching order events: the producer or a new EventBridge rule?
Show answer
Add a new rule and target when possible. The producer can continue publishing the same event.