Event buses, rules, targets, and patterns
coreintermediateAn event bus receives events and routes them. A rule watches the bus for events matching an event pattern (or a schedule) and sends matches to one or more targets. An archive stores matched events so you can replay them later.
Think of it as
The event bus is a mail room; a rule is a standing instruction like "any package matching this label, forward to these five desks." An archive is a copy of every matching package kept in storage, so you can resend the batch later without the sender resending anything.
What we're doing: Create a rule that matches a domain event and fans it out to two targets.
- 2
- "source" and "detail-type" narrow the match to one producer and one event type, before "detail" filters on the payload itself.
- 4
- A numeric matcher on "amount" only matches events where the field satisfies the comparison — not every OrderPlaced event.
Why this works: Both targets receive the same matching event independently and run in parallel — the Lambda function and the SQS queue do not know about each other, and a failure in one does not block delivery to the other.
Writing a pattern that is broader than intended, so unrelated events reach the target
Wrong
Better
What you see: A target built to handle one event type silently receives every event type the source ever emits — OrderPlaced, OrderCancelled, OrderRefunded — and either errors on the unexpected shapes or, worse, processes them incorrectly without erroring at all.
Why: An event pattern matches on whatever fields you specify and ignores the rest — omitting "detail-type" means any event from that source matches, regardless of what kind of event it is.
- Event source
- leads to Event bus (PutEvents)
- Event bus
- leads to Rule (pattern or schedule) (evaluated against)
- leads to Archive (optional) (matching events copied)
- Rule (pattern or schedule)
- leads to Target(s) (matched → invoke (up to 5, parallel))
- Target(s)
- Archive (optional)
Remember: Bus routes, rule matches (pattern or schedule) and fans out to up to 5 parallel targets, archive stores a copy for replay back to the same source bus. Cross-account needs a resource policy on the receiving bus plus a rule on the sending side.
See also: domain events vs commands · loosely coupled event driven design

