Sub topic 13
Archiving and replaying events
This chapter assumes you can publish events to a custom bus, write rules and event patterns, and read basic CLI output. Archive and replay let you store events that pass through a bus and send them through the bus again later.
Why archive events
A rule delivers an event once and then the event is gone. Archiving helps in three situations:
- A target had a bug, and you need to reprocess the events it handled badly.
- You added a new rule and want to test it against real past traffic.
- You need to rebuild a downstream data store.
An archive belongs to one event bus. It stores a copy of the events that match its event pattern. If you give no pattern, it stores every event on the bus.
Create an archive
First write a pattern file that limits the archive to the events you care about. It uses the same syntax as a rule pattern.
{
"source": ["com.example.orders"],
"detail-type": ["OrderPlaced"]
}Then create the archive from the bus ARN. The --retention-days option sets how long events are kept. A value of 0 keeps them indefinitely.
aws events create-archive \
--archive-name orders-archive \
--event-source-arn arn:aws:events:us-east-1:123456789012:event-bus/orders-bus \
--event-pattern file://archive-pattern.json \
--retention-days 30Only events published after the archive exists are stored. Events that arrived earlier cannot be added.
Start a replay
A replay reads events from an archive, within a start and end time, and puts them back on a bus. The source is the archive ARN. The destination is the bus ARN.
aws events start-replay \
--replay-name orders-replay-1 \
--event-source-arn arn:aws:events:us-east-1:123456789012:archive/orders-archive \
--destination '{"Arn":"arn:aws:events:us-east-1:123456789012:event-bus/orders-bus"}' \
--event-start-time 2026-11-25T00:00:00Z \
--event-end-time 2026-11-25T12:00:00ZCheck progress with aws events describe-replay --replay-name orders-replay-1. The State field moves from STARTING to RUNNING and then to COMPLETED. Use aws events cancel-replay to stop a replay that is running.
Limit which rules receive replayed events
By default, replayed events go through every matching rule on the bus. Live targets then receive old events again. To avoid this, add FilterArns to the destination with the ARNs of the rules that should receive the replay:
{
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/orders-bus",
"FilterArns": [
"arn:aws:events:us-east-1:123456789012:rule/orders-bus/high-value-orders"
]
}Behavior to plan for
- Same bus only. A replay can only send events to the bus the archive was created from. To test elsewhere, use a rule that forwards to another bus or account.
- Replay marker. Replayed events keep their original
timevalue. They also get areplay-namefield at the top level. A rule can match this field to treat replays differently from live events. - Ordering. Replayed events are not guaranteed to arrive in their original order or at their original pace.
- Duplicates. Targets see the same business event again. Make consumers idempotent. This means handling a repeated
orderIdwithout repeating its side effects. - Cost. You pay for stored archive data. Use a pattern and a retention period instead of archiving everything forever.
Common errors
- Archive looks empty. Events only appear after the archive is created, and they can take a few minutes to show up. Also confirm the archive pattern matches the events.
- Replay is rejected. The destination bus must match the archive's source bus, and the end time must be after the start time.
- Nothing is delivered. If no rule matches the replayed events, they go nowhere. Test the pattern with
aws events test-event-patternfirst.
Exercise
You fixed a bug in a Lambda function that is the target of the rule high-value-orders. You want to reprocess yesterday's orders through that rule only, without alerting other rules on the same bus. Which option makes this possible, and what must you do in the consumer before you run it?
Show answer
Start a replay from the bus's archive for yesterday's time window. Set FilterArns in the replay destination to the ARN of the high-value-orders rule so other rules do not receive the events. Make the Lambda function idempotent first, because it will see orders it already processed.