serverlesseventbridgestepfunctions
- Published on
Replaying Amazon EventBridge events with AWS Step Functions
I want to share with you an experimental Step Functions pattern that allows you to replay events from eventbridge at the same time they happened.
- David Boyne
- Published on • 3 min read
Just wanted to share with you a quick pattern I put together to help you replay events back into Amazon EventBridge at the same time they occurred.
For example if you have a list of events that played over yesterday throughout the day, you can use this pattern to replay them today at exactly the same time.
EventBridge already has a great way to replay & archive events, but I wanted to explore other ways and solutions we can use to replay events, mainly focusing on the time the events were raised.
In this short blog post I will share with you how this pattern works with AWS Step Functions and how you can try it yourself.
•••Why replay events at the same time they occurred?
When replaying events you may not really care about the time they were raised and just want to raise them again (maybe in lower environments for example).
I wanted to explore a pattern of replaying events at the same time they occurred in the past. Use cases for this pattern might be limiting, but I wanted to explore what was possible with Step Functions and share that solution with you all.
•••How does the EventBridge Replayer pattern work?
The pattern itself is quite simple. It takes an array of events, maps over them, transforms the date of the events, and uses Step Functions wait state to then put events onto the given event bus.
The event timestamp is converted to today and the hours, minutes and seconds are left untouched. This allows us to replay the events today as the same time they occurred in the past.
Using the choice state we check to make sure the event is in the future. (for example if it’s currently 13:00pm, and the event was at 09:00, that event would be skipped).
Once the time has elapsed PutEvents
is then triggered to raise the event on your event bus.
Where can I get started?
If you would like to experiment with the pattern head over to https://serverlessland.com/workflows/eventbridge-replay-events and follow the instructions.
Any thoughts, feedback or changes I would love to hear them. This pattern is completely experimental and I wanted to see if it could be done and also help others.
Summary
Amazon EventBridge already has a solution for retrying events, I wanted to take this further and see if we could replay events using Step Functions with timers and looks like something is possible with a simple workflow!
If you are interesting in replaying events, feel free to get in contact. I would love to explore more patterns or ideas you have and see what we can do!
Until next time