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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠