Sub topic 3
Event buses: default, custom, and partner
This chapter assumes you know AWS accounts and regions, can use the AWS CLI, can read JSON, and have a basic grasp of IAM. It builds on the previous chapter, which covered the structure of an event.
What an event bus is
An event bus is a named router in one account and one region. Producers send events to it. Rules on the same bus match those events and deliver them to targets. A rule only sees events that arrive on its own bus. A rule on one bus never matches events sent to another bus.
There are three kinds of bus.
| Bus type | Created by | Typical producers | Can you delete it? |
|---|---|---|---|
| Default | AWS, in every region of every account | AWS services such as EC2, S3, and CodePipeline | No |
| Custom | You | Your own applications | Yes |
| Partner | A partner event source you accept | SaaS providers such as Zendesk or Datadog | Yes |
The default bus
Every region in your account already has a bus named default. AWS services publish their events here automatically, for example an EC2 instance changing state. You do not publish these events yourself. You only write rules that match them.
You can also send your own events to the default bus. For anything beyond a quick test, a custom bus is a better choice, as the next section explains.
Custom buses
A custom bus holds events from your own applications. Create one with a single command:
aws events create-event-bus --name orders-busThe command returns the bus ARN, which has this form:
arn:aws:events:us-east-1:123456789012:event-bus/orders-busUse custom buses to separate concerns:
- Isolation of traffic. Order events do not mix with AWS service events or with another team's events.
- Separate permissions. Each bus has its own resource policy. You can let another account publish to
orders-buswithout exposing the default bus. - Separate archives and rules. Archive, replay, and rule limits apply per bus.
Producers choose the bus with the EventBusName field of each entry in PutEvents. If you leave it out, the event goes to the default bus. This is a common bug: events appear to vanish because the rule is on orders-bus while the event went to default.
aws events list-event-busesThis lists every bus in the current region, including default.
Partner buses
A partner event source lets a SaaS provider send events into your account. The flow has three steps.
- The partner creates a partner event source for your account ID.
- In your account, the source appears as pending. You create a partner event bus by accepting it.
- You write rules on that bus as you would on any other.
The bus name comes from the source and usually starts with aws.partner/. You cannot publish to a partner bus yourself. Only the partner can.
How the three fit together
Common errors
- Wrong bus. Rules created without
--event-bus-namego on the default bus. When you use a custom bus, pass--event-bus-nametoput-ruleandput-targetsas well. - Wrong region. A bus exists in one region. A producer in
us-west-2does not reach a bus inus-east-1unless you route it with a rule (a later chapter). - Assuming a bus has a schema. A bus accepts any valid event. Validation happens in your patterns, not on the bus.
Exercise
A service publishes an event with PutEvents and no EventBusName. Your rule is on a custom bus named orders-bus and the event matches its pattern. Does the rule fire, and why?
Show answer
No. With no EventBusName, the event goes to the default bus. The rule on orders-bus never sees it. Set EventBusName to orders-bus in the entry.
Exercise
Why might you choose a custom bus over the default bus for application events?
Show answer
A custom bus separates your events from AWS service events, and it has its own resource policy, so you can grant other accounts access to it without exposing the default bus.