Day of the week Cron Job Not Working

0

Hi. I have tried multiple cron jobs including examples from AWS documentation without success. I would like to create a cron expression that runs daily Monday to Friday at 0630 UTC. The one I have been trying is cron(0 30 6 ? * MON-FRI *) and variations of this. If I do a single day of the week it works but not if I do a range of days of the week.

asked 8 months ago852 views
2 Answers
0
Accepted Answer

Hello.

I think it would work with the following cron.
https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-expressions.html

cron(30 6 ? * MON-FRI *)
profile picture
EXPERT
answered 8 months ago
profile pictureAWS
EXPERT
reviewed 8 months ago
  • Hi. Thank you for you answer. Unfortunately that also gets flagged as invalid. The exact error is: InvalidSchedule: Schedule expression cron(30 6 ? * MON-FRI *) is currently not accepted. Supported expressions are every half, 1, 2, 4, 8 or 12 hour(s), every specified day and time of the week, or a specific day in a specific week of the month Supported examples are: cron(0 0/30 * 1/1 * ? *), cron(0 0 0/4 1/1 * ? *), cron (0 0 10 ? * SUN *), cron (0 0 10 ? * * *), cron(0 0 ? * TUE#2 *)

  • Systems manager. I am using state manager to spin up and shut down EC2 instances.

  • Thank you for your reply. By the way, which service do you set up cron for? The above cron is not available when used with Systems Manager State Manager. As described in the following document, you should only be able to configure cron to run at specific times. https://docs.aws.amazon.com/systems-manager/latest/userguide/reference-cron-and-rate-expressions.html#reference-cron-and-rate-expressions-association

    Associations support the following cron expressions: every 1/2, 1, 2, 4, 8, or 12 hours; every day, every week, every nth day, or the last x day of the month at a specific time.

  • Ok. I see. What do you mean by service? I am using it to start and stop EC2 instances at set times and days of the week.

  • Sorry, my comments were misplaced.

    Systems manager. I am using state manager to spin up and shut down EC2 instances.

    For such use cases, it may be possible to use the EventBridge scheduler. EventBridge scheduler supports many APIs and allows flexible cron settings. https://docs.aws.amazon.com/eventbridge/latest/userguide/scheduler.html

0

Have you considered using an Auto Scaling group with a scheduled scaling policy for this? One additional benefit to this approach would be the EC2 instance health check and automated replacement if an instance becomes unhealthy during your "in service" period. More details on using a scheduled scaling policy with Auto Scaling groups can be found here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html

AWS
ASGDude
answered 8 months 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