Querying Your EventBridge Scheduled Events
EventBridge Scheduled Events are a fantastic addition to the AWS event driven ecosystem. However, they do have an issue... observability. If you’re looking for a reliable way to track these events without the issues of the EventBridge API, I’ve got a practical solution for you.
Introduction
The code for this article can be found here:
Independently to the core logic of the schedule creation, our service does the following steps:
- CloudTrail picks up the EventBridge API events and they are published on the main Event Bus
- An EventBridge rule filters for these events and pushes them to an SQS queue
- The queue will batch the messages and send them to the
ScheduleMonitorFunction. This Lambda will process the messages and create/update relevant records in DynamoDb
A queue is used during Step 2 because CloudTrail will not guarantee the order of events that are delivered. We need to ensure that changes are processed in order, so SQS will re-batch the messages, which are then sorted by the eventTime as they are processed in the ScheduleMonitorFunction Lambda Function.
To see how this works, deploy the demo repo and run the SeedSchedulesFunction. This creates three scheduled events, waits a few seconds then modifies one of them and deleted one of them. This demonstrate the functionality of the solution.
aws lambda invoke --function-name SeedSchedulesFunction outfile.txt
Items are stored with a Time to Live (TTL) so they will expire and be removed from DynamoDB 30 days after the firing time.
Limitations and Considerations
Fired Events: This solution won’t explicitly track fired events, but since AWS guarantees “at least once delivery,” it’s safe to assume fired schedules have actually been fired.
Storage Costs: DynamoDB storage and CloudTrail logs will incur additional costs, so optimise your queries and retention policies.
Next Steps
This pattern is extensible for further uses. Options that could be considered include:
Analytics: Push data to Redshift, S3, or Athena for advanced querying and analytics.
Payload Recovery: Store payloads of scheduled events for disaster recovery or debugging.
About Me
I’m Ian, an AWS Serverless Specialist and AWS Certified Cloud Architect based in the UK. I work as an independent consultant, having worked across multiple sectors, with a passion for Aviation.
Let's connect on
SOCIAL SHARE CARD GENERATOR