Is it possible to set up Amazon EC2 auto-scaling for particular days of the week?

1.8k views Asked by At

I need to have a different auto-scaling policy for weekdays vs weekend.

So far I figured out how to set up the same policy for every day. The cmd call and the CRON string look like that:

as-put-scheduled-update-group-action  TNUPWN --auto-scaling-group  TNASG --region us-west-2 --recurrence "30 18 * * *" --desired-capacity 1

But when I try to set a CRON string for week days only e.g.

30 7 ? * MON-FRI * 
or 
0 30 7 ? * MON-FRI *

I am getting the error

as-put-scheduled-update-group-action:  Malformed input-Given recurrence string:30 1 ? * MON-FRI * is
 invalid
Usage:
as-put-scheduled-update-group-action
        ScheduledActionName  --auto-scaling-group  value [--desired-capacity
       value ] [--end-time  value ] [--max-size  value ] [--min-size  value ]
       [--recurrence  value ] [--start-time  value ] [--time  value ]
        [General Options]

Any ideas? Is it even possible with AWS?

3

There are 3 answers

0
andreobrown On

I think the problem is with your cron string. Try using digits (instead of day abbreviations).

Also, you could implement it this way:

  1. Setup scheduled group action for every Friday at midnight to increase capacity.

    --recurrence 0 0 * * 5 *

  2. Setup scheduled group action for every Sunday at midnight to reduce capacity.

    --recurrence 0 0 * * 7 *

This article has some sample commands with properly formatted cron strings:

http://www.newvem.com/how-to-configure-aws-cloud-auto-scaling-to-scale-based-on-a-schedule/

And here is a cron format reference:

http://www.nncron.ru/help/EN/working/cron-format.htm

0
Ben Bunk On

The problem is that AWS only supports the 5 digit notation as opposed to the 6 digit notation in your example.

The AWS official blog announcement links directly to the Wikipedia page for cron which has the 5 digit notation at the top.

Your schedule corrected:

  • 30 7 ? * MON-FRI
0
NickBeaugié On

If it helps anyone else, I had the following Cron strings rejected:

0 0 1 1/1 * ? TUE-SAT
0 0 1 1/1 * ? Tue-Sat
0 0 1 * * ? Tue-Sat
0 1 ? * TUE-SAT

All of these had been found valid by this online utility: http://cronexpressiondescriptor.azurewebsites.net

Finally, it worked with this one:

0 1 * * TUE-SAT

So AWS must have their own particular syntax.