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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ