Scheduled scaling for Amazon EC2 Auto Scaling - Amazon EC2 Auto Scaling

Scheduled scaling for Amazon EC2 Auto Scaling

With scheduled scaling, you can set up automatic scaling for your application based on predictable load changes. You create scheduled actions that increase or decrease your group's desired capacity at specific times.

For example, you experience a regular weekly traffic pattern where load increases midweek and declines toward the end of the week. You can configure a scaling schedule in Amazon EC2 Auto Scaling that aligns with this pattern:

  • On Wednesday morning, one scheduled action increases capacity by increasing the previously set desired capacity of the Auto Scaling group.

  • On Friday evening, another scheduled action decreases capacity by decreasing the previously set desired capacity of the Auto Scaling group.

These scheduled scaling actions allow you to optimize costs and performance. Your application has sufficient capacity to handle the midweek traffic peak, but does not over-provision unneeded capacity at other times.

You can use scheduled scaling and scaling policies together to get the benefits of both approaches to scaling. After a scheduled scaling action runs, the scaling policy can continue to make decisions about whether to further scale capacity. This helps you ensure that you have sufficient capacity to handle the load for your application. While your application scales to match demand, current capacity must fall within the minimum and maximum capacity that was set by your scheduled action.

How scheduled scaling works

To use scheduled scaling, create scheduled actions, which tell Amazon EC2 Auto Scaling to perform scaling activities at specific times. When you create a scheduled action, you specify the Auto Scaling group, when the scaling activity should occur, the new desired capacity, and optionally a new minimum capacity and a new maximum capacity. You can create scheduled actions that scale one time only or that scale on a recurring schedule.

At the specified time, Amazon EC2 Auto Scaling scales based on the new capacity values, by comparing current capacity to the specified desired capacity.

  • If current capacity is less than the specified desired capacity, Amazon EC2 Auto Scaling scales out, or adds instances, to the specified desired capacity.

  • If current capacity is greater than the specified desired capacity, Amazon EC2 Auto Scaling scales in, or removes instances, to the specified desired capacity.

A scheduled action sets the group's desired, minimum, and maximum capacity at the date and time specified. You can create a scheduled action for only one of these capacities at a time, for example, desired capacity. However, there are some cases where you must include the minimum and maximum capacity to ensure that the desired capacity that you specified in the action is not outside of these limits.

Recurring schedules

To create a recurring schedule using the AWS CLI or an SDK, specify a cron expression and a time zone to describe when that scheduled action is to recur. You can optionally specify a date and time for the start time, the end time, or both.

To create a recurring schedule using the AWS Management Console, specify the recurrence pattern, time zone, start time, and optional end time of your scheduled action. All of the recurrence pattern options are based on cron expressions. Alternatively, you can write your own custom cron expression.

The supported cron expression format consists of five fields separated by white spaces: [Minute] [Hour] [Day_of_Month] [Month_of_Year] [Day_of_Week]. For example, the cron expression 30 6 * * 2 configures a scheduled action that recurs every Tuesday at 6:30 AM. The asterisk is used as a wildcard to match all values for a field. For other examples of cron expressions, see https://crontab.guru/examples.html. For information about writing your own cron expressions in this format, see Crontab.

Choose your start and end times carefully. Keep the following in mind:

  • If you specify a start time, Amazon EC2 Auto Scaling performs the action at this time, and then performs the action based on the specified recurrence.

  • If you specify an end time, the action stops repeating after this time. A scheduled action does not persist in your account once it has reached its end time.

  • The start time and end time must be set in UTC when you use the AWS CLI or an SDK.

Time zone

By default, the recurring schedules that you set are in Coordinated Universal Time (UTC). You can change the time zone to correspond to your local time zone or a time zone for another part of your network. When you specify a time zone that observes Daylight Saving Time (DST), the action automatically adjusts for DST.

The valid values are the canonical names for time zones from the Internet Assigned Numbers Authority (IANA) Time Zone database. For example, US Eastern time is canonically identified as America/New_York. For more information, see https://www.iana.org/time-zones.

Location-based time zones such as America/New_York automatically adjust for DST. However, a UTC-based time zone such as Etc/UTC is an absolute time and will not adjust for DST.

For example, you have a recurring schedule whose time zone is America/New_York. The first scaling action happens in the America/New_York time zone before DST starts. The next scaling action happens in the America/New_York time zone after DST starts. The first action starts at 8:00 AM UTC-5 in local time, while the second time starts at 8:00 AM UTC-4 in local time.

If you create a scheduled action using the AWS Management Console and specify a time zone that observes DST, both the recurring schedule and the start and end times automatically adjust for DST.

Considerations

When you create a scheduled action, keep the following in mind:

  • The order of execution for scheduled actions is guaranteed within the same group, but not for scheduled actions across groups.

  • A scheduled action generally runs within seconds. However, the action might be delayed for up to two minutes from the scheduled start time. Because scheduled actions within an Auto Scaling group are executed in the order that they are specified, actions with scheduled start times close to each other can take longer to execute.

  • You can temporarily turn off scheduled scaling for an Auto Scaling group by suspending the ScheduledActions process. This helps you prevent scheduled actions from being active without having to delete them. You can then resume scheduled scaling when you want to use it again. For more information, see Suspend and resume Amazon EC2 Auto Scaling processes.

  • After creating a scheduled action, you can update any of its settings except the name.

Create a scheduled action

To create a scheduled action for your Auto Scaling group, use one of the following methods:

Console
To create a scheduled action
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/, and choose Auto Scaling Groups from the navigation pane.

  2. Select the check box next to your Auto Scaling group.

    A split pane opens up in the bottom of the page.

  3. On the Automatic scaling tab, in Scheduled actions, choose Create scheduled action.

  4. Enter a Name for the scheduled action.

  5. For Desired capacity, Min, Max, choose the new desired capacity of the group and the new minimum and maximum size limits. The desired capacity must be equal to or greater than the minimum group size, and equal to or less than the maximum group size.

  6. For Recurrence, choose one of the available options.

    • If you want to scale on a recurring schedule, choose how often Amazon EC2 Auto Scaling should run the scheduled action.

      • If you choose an option that begins with Every, the cron expression is created for you.

      • If you choose Cron, enter a cron expression that specifies when to perform the action.

    • If you want to scale only once, choose Once.

  7. For Time zone, choose a time zone. The default is Etc/UTC.

    All of the time zones listed are from the IANA Time Zone database. For more information, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.

  8. Define a date and time for Specific start time.

    • If you chose a recurring schedule, the start time defines when the first scheduled action in the recurring series runs.

    • If you chose Once as the recurrence, the start time defines the date and time for the schedule action to run.

  9. (Optional) For recurring schedules, you can specify an end time by choosing Set End Time and then choosing a date and time for End by.

  10. Choose Create. The console displays the scheduled actions for the Auto Scaling group.

AWS CLI

To create a scheduled action, you can use one of the following example commands. Replace each user input placeholder with your own information.

Example: To scale one time only

Use the following put-scheduled-update-group-action command with the --start-time "YYYY-MM-DDThh:mm:ssZ" and --desired-capacity options.

aws autoscaling put-scheduled-update-group-action --scheduled-action-name my-one-time-action \ --auto-scaling-group-name my-asg --start-time "2021-03-31T08:00:00Z" --desired-capacity 3
Example: To schedule scaling on a recurring schedule

Use the following put-scheduled-update-group-action command with the --recurrence "cron expression" and --desired-capacity options.

aws autoscaling put-scheduled-update-group-action --scheduled-action-name my-recurring-action \ --auto-scaling-group-name my-asg --recurrence "0 9 * * *" --desired-capacity 3

By default, Amazon EC2 Auto Scaling runs the specified recurrence schedule based on the UTC time zone. To specify a different time zone, include the --time-zone option and the name of the IANA time zone, as in the following example.

--time-zone "America/New_York"

For more information, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.

View scheduled action details

To view details of upcoming scheduled actions for your Auto Scaling group, use one of the following methods:

Console
To view scheduled action details
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/, and choose Auto Scaling Groups from the navigation pane.

  2. Select your Auto Scaling group.

  3. On the Automatic scaling tab, in the Scheduled actions section, you can view upcoming scheduled actions.

Note that the console shows the values for Start time and End time in your local time with the UTC offset in effect at the specified date and time. The UTC offset is the difference, in hours and minutes, from local time to UTC. The value for Time zone shows your requested time zone, for example, America/New_York.

AWS CLI

Use the following describe-scheduled-actions command.

aws autoscaling describe-scheduled-actions --auto-scaling-group-name my-asg

If successful, this command returns output similar to the following.

{ "ScheduledUpdateGroupActions": [ { "AutoScalingGroupName": "my-asg", "ScheduledActionName": "my-recurring-action", "Recurrence": "30 0 1 1,6,12 *", "ScheduledActionARN": "arn:aws:autoscaling:us-west-2:123456789012:scheduledUpdateGroupAction:8e86b655-b2e6-4410-8f29-b4f094d6871c:autoScalingGroupName/my-asg:scheduledActionName/my-recurring-action", "StartTime": "2020-12-01T00:30:00Z", "Time": "2020-12-01T00:30:00Z", "MinSize": 1, "MaxSize": 6, "DesiredCapacity": 4 } ] }

Verify scaling activities

To verify the scaling activities associated with scheduled scaling, see Verify a scaling activity for an Auto Scaling group.

Delete a scheduled action

To delete a scheduled action, use one of the following methods:

Console
To delete a scheduled action
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/, and choose Auto Scaling Groups from the navigation pane.

  2. Select your Auto Scaling group.

  3. On the Automatic scaling tab, in Scheduled actions, select a scheduled action.

  4. Choose Actions, Delete.

  5. When prompted for confirmation, choose Yes, Delete.

AWS CLI

Use the following delete-scheduled-action command.

aws autoscaling delete-scheduled-action --auto-scaling-group-name my-asg \ --scheduled-action-name my-recurring-action

Limitations

  • The names of scheduled actions must be unique per Auto Scaling group.

  • A scheduled action must have a unique time value. If you attempt to schedule an activity at a time when another scaling activity is already scheduled, the call is rejected and returns an error indicating that a scheduled action with this scheduled start time already exists.

  • You can create a maximum of 125 scheduled actions per Auto Scaling group.