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.

已提問 8 個月前檢視次數 774 次
2 個答案
0
已接受的答案

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
專家
已回答 8 個月前
profile pictureAWS
專家
已審閱 8 個月前
  • 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
已回答 7 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南