Cron expression Aws to run every 5 minutes after EventBridge (Cloudwatch trigger) enables

6.5k views Asked by At

I've seen several examples and all of them just trigger one job at a specific time, I have right now: 0 */5 * ? * * and it triggers at mins 0,5,10, and on. But, I need the trigger to run at +5 of the moment that the trigger was enabled.

So, if service becomes enable at 12:07 pm I need it to run then at 12:12 pm and on. Is there a way to accomplish this?

2

There are 2 answers

3
natz On BEST ANSWER

Like you mentioned offsets are part of the solution to your problem.

0 */5+your_offset * ? * *

Now coming to what could be your offset:

Let's say cloudwatch-event bridge is enabled at some 12:07, (You can get that info from event details timestamp.)

your_offset = 7 + 5
// so your cron becomes :  0 */5+12 * ? * *

Or in general your

offset = the minute part of timestamp + 5 
// for your to schedule 5 mins after service is enabled
0
Dev Magician On

Solution is simple:

Before create the rule check the minute time at that moment

time_minutes_now */5 * ? * *