Search code examples
amazon-web-servicescronamazon-cloudwatch-events

How to make cron run only 42 times in 10 minute intervals?


I need to make a job run 42 times in intervals of 10 minutes. I will be doing this using AWS Scheduled Task, which has the following cron syntax: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

The basic arithmetic formula I came up with:

42 * 10 minutes = 420 minutes / 60 minutes = 7 hours.

That means I want the Scheduled Task to run in intervals of 10 minutes over 7 hours. Once it reaches that 7 hours, it just no longer runs for the rest of the day.

Given this, I came up with this expression?

cron(1/10,15-21,*,*,?,*) 

Is this expression accurate and most efficient for my needs?


Solution

  • The syntax for the expression should actually be cron(1/10 15-21 * * ? *) so you would want to remove the commas between.

    You have offset the minute part of the expression by 1 so it will run at 1,11,21,31,41,51. If you simply wanted it to run once every 10 minutes then you could do */10 instead.

    This will run 6 times in an hour 7 hours so that checks out as your count of 42 which is what you expect ranging from 15:01 to 21:51.

    Just be aware that this is executed in UTC so ensure that the times match any time zone that you're expecting it to operate it.