AWS EventBridge Scheduler Rules Fire Immediately After Terraform Deployment Outside Scheduled Window

0

Hello everyone,

I’m running into a problem where my EventBridge Scheduler rules fire immediately after a deployment, even though they shouldn’t. Here’s what’s happening:

Infrastructure as code: I manage all of my schedulers in Terraform.

Scheduling details: Each rule uses the cron expression cron(0/10 9-13,14-19 ? * MON-SAT *) and is set to the Europe/Paris time zone.

Deployment timing: I rolled out my changes at 13:30 CET—outside the 09:00–13:00 and 14:00–19:00 windows.

Unexpected behavior: Despite the off‑hours deployment, the schedulers triggered my Lambda functions as soon as Terraform finished.

Please note that the schedulers are manually added and not configured using terraform

How can I prevent this from happening again ?

  • Hi, sorry for the confusion, I manage them manually from the console , The event sent is a custom event. The issue is that the cron is configured to not run at the time that i did the deployment but somehow after the deployement was done, i checked the logs and saw that the schedules were running. Went to check the schedules why they got triggered but nth was changed in them. And when i saw the next triggers. They were all in the unallowed time to call. To give you more context , the time that the schedulers was not supposed to trigger is between 1 and 2. Deployment happend at 1:30 , the schedulers triggered the lambdas at 1:40 then 1:50 then 2:00. Which is something that is not supposed to happen

  • Could you please clarify how you manage these schedulers? You first mention that you manage them in Terraform but then later that they are manually added outside Terraform?

    What is the event that you receive when the Lambda function gets triggered?

2 Answers
0

In Amazon EventBridge cron expressions, ranges are inclusive of both the start and end values. Hence, if you are defining hours as 9-13,14-19 the rule is active from 09:00 to 13:59 and 14:00 to 19:59 which effectively makes it active from 9:00 AM to 7:59 PM in Europe/Paris.

You can amend your cron expression to be cron(0/10 9-12,14-19 ? * MON-SAT *) but it will miss the run at 13. If this run is important, I am not sure you can achieve so with a single cron expression but you could create just another one for 13 with the same Lambda function as a target.

The AWS web console displays the next 10 trigger dates when you define a cron expression, you can use that to confirm it runs when you want to.

profile pictureAWS
answered 25 days ago
  • @Hanna Hinn curious to know if the above helped. Cheers.

0

The behavior you're experiencing with AWS EventBridge Scheduler rules firing immediately after deployment, even outside the scheduled window, is not typical and suggests a potential misconfiguration or misunderstanding of how EventBridge Scheduler operates.

EventBridge Scheduler rules should only run at the times specified by their cron expressions. In your case, with the expression cron(0/10 9-13,14-19 ? * MON-SAT *), the rules should only trigger every 10 minutes between 9 AM-1 PM and 2 PM-7 PM on Monday through Saturday, in the Europe/Paris time zone.

To address this issue and prevent immediate firing after deployment, consider the following:

  1. Double-check your cron expression: Ensure it accurately represents your intended schedule. The current expression looks correct based on your description.

  2. Verify the time zone: Confirm that the Europe/Paris time zone is correctly set for each rule. Time zone mismatches can cause unexpected behavior.

  3. Use flexible time windows: Consider implementing flexible time windows for your schedules. This feature allows EventBridge Scheduler to invoke targets within a specified time frame after the scheduled time, which can improve schedule reliability and potentially mitigate issues with immediate firing.

  4. Check for default state: When creating or updating schedules, ensure that the state is set to ENABLED only when you want the schedule to be active. You might want to set it to DISABLED initially and enable it at an appropriate time.

  5. Review your Terraform configuration: Although you mentioned that the schedulers are manually added, review your Terraform code to ensure it's not inadvertently triggering the schedulers or modifying their configurations during deployment.

  6. Implement a delay: If the issue persists, you could implement a short delay or cool-down period after deployment before enabling the schedulers.

  7. Monitor and log: Set up detailed logging and monitoring for your EventBridge Scheduler rules to track when and why they're being triggered. This can help identify any unexpected behavior.

If these steps don't resolve the issue, you may need to contact AWS support for further assistance, as this behavior is not standard for EventBridge Scheduler.
Sources
Configuring flexible time windows in EventBridge Scheduler - EventBridge Scheduler
Changing the schedule state in EventBridge Scheduler - EventBridge Scheduler

profile picture
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions