Auto Scaling
Developer Guide (API Version 2011-01-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

Scheduled Scaling

Scaling based on a schedule allows you to scale your application in response to predictable load changes. For example, every week the traffic to your web application starts to increase on Wednesday, remains high on Thursday, and starts to decrease on Friday. You can plan your scaling activities based on the predictable traffic patterns of your web application.

To configure your Auto Scaling group to scale based on a schedule, you need to create scheduled actions. A scheduled action tells Auto Scaling to perform a scaling action at certain time in future. To create a scheduled scaling action, you specify the start time at which you want the scaling action to take effect, and you specify the new minimum, maximum, and desired size you want for that group at that time. At the specified time, Auto Scaling updates the group to set the new values for minimum, maximum, and desired sizes, as specified by your scaling action.

You can create scheduled actions for scaling one time only or for scaling on a recurring schedule.

Programming Considerations for Scheduled Actions

When you create a scheduled action, keep the following programming considerations in mind.

  • Auto Scaling guarantees the order of execution for scheduled actions within the same group, but not for scheduled actions across groups.

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

  • You can schedule a scheduled action for up to a month in the future.

  • You can create a maximum of 125 scheduled actions per month per Auto Scaling group. This allows scaling four times a day for a 31-day month for each Auto Scaling group.

  • A scheduled action must have a unique time value. If you attempt to schedule an activity at a time when another existing activity is already scheduled, the call is rejected with an error message noting the conflict.

Scheduling Scaling Using the AWS CLI

Complete the following tasks to create a scheduled action to scale your Auto Scaling group.

Create a Launch Configuration

Use the following create-launch-configuration command to create a launch configuration named my-test-lc:

aws autoscaling create-launch-configuration --launch-configuration-name my-test-lc --image-id ami-514ac838 --instance-type m1.small --associate-public-ip-address

Create an Auto Scaling Group

Use the following create-auto-scaling-group command to create an Auto Scaling group named my-test-asg.

aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-test-asg --launch-configuration-name my-test-lc --max-size 5 --min-size 1 --availability-zones "us-east-1e"

Create a Schedule for Scaling Actions

You can create a schedule for scaling one time only or for scaling on a recurring schedule.

To schedule scaling for one time only

To increase the number of running instances in your Auto Scaling group at a specific time, use the following put-scheduled-update-group-action command to create a scheduled action named ScaleUp that runs at the specified time (specified in "YYYY-MM-DDThh:mm:ssZ" format in UTC time):

aws autoscaling put-scheduled-update-group-action --scheduled-action-name ScaleUp --auto-scaling-group-name my-test-asg --start-time "2013-05-12T08:00:00Z" --desired-capacity 3 

To decrease the number of running instances in your Auto Scaling group at a specific time, use the following as-put-scheduled-update-group-action command to create a scheduled action named ScaleDown that runs at the specified time (specified in "YYYY-MM-DDThh:mm:ssZ" format in UTC time):

aws autoscaling put-scheduled-update-group-action --scheduled-action-name ScaleDown --auto-scaling-group-name my-test-asg --start-time "2013-05-13T08:00:00Z" --desired-capacity 1 

To schedule scaling on a recurring schedule

You can specify a recurrence schedule using the Unix cron syntax format. For more information about cron syntax, see the Cron Wikipedia entry.

Use the following put-scheduled-update-group-action command to create a scheduled action named scaleup-schedule-year that runs at 00:30 hours on the first of January, June, and December each year:

aws autoscaling put-scheduled-update-group-action --scheduled-action-name scaleup-schedule-year --auto-scaling-group-name my-test-asg --recurrence "30 0 1 1,6,12 0" --desired-capacity 3 

Scheduling Scaling Using the Auto Scaling CLI

Complete the following tasks to create a scheduled action to scale your Auto Scaling group. For more information about the command syntax of any of these commands, use the --help option with the command or see the Auto Scaling Quick Reference Card.

Create a Launch Configuration

Use the following as-create-launch-config command to create a launch configuration named my-test-lc:

as-create-launch-config my-test-lc --image-id ami-514ac838 --instance-type m1.small 

Create an Auto Scaling Group

Use the following as-create-auto-scaling-group command to create an Auto Scaling group named my-test-asg.

as-create-auto-scaling-group my-test-asg --launch-configuration my-test-lc --availability-zones "us-east-1e" --max-size 5 --min-size 1 

(Optional) Verify Your Auto Scaling Group

Use the following as-describe-auto-scaling-groups command to get information about the my-test-asg group:

as-describe-auto-scaling-groups my-test-asg --headers

The following is an example response that shows that Auto Scaling launched an instance using my-test-lc, and the instance is running (InService):

AUTO-SCALING-GROUP  GROUP-NAME   LAUNCH-CONFIG  AVAILABILITY-ZONES  MIN-SIZE  MAX-SIZE  DESIRED-CAPACITY  TERMINATION-POLICIES
AUTO-SCALING-GROUP  my-test-asg  my-test-lc     us-east-1e          1         5        1             Default
INSTANCE  INSTANCE-ID  AVAILABILITY-ZONE  STATE      STATUS     LAUNCH-CONFIG
INSTANCE  i-cbd7caba   us-east-1e       InService  InService  my-test-lc

Create a Schedule for Scaling Actions

You can create a schedule for scaling one time only or for scaling on a recurring schedule.

To schedule scaling for one time only

To increase the number of running instances in your Auto Scaling group at a specific time, use the following as-put-scheduled-update-group-action command to create a scheduled action named ScaleUp that runs at the specified time (specified in "YYYY-MM-DDThh:mm:ssZ" format in UTC time):

as-put-scheduled-update-group-action ScaleUp --auto-scaling-group my-test-asg --start-time "2013-05-12T08:00:00Z" --desired-capacity 3 

To decrease the number of running instances in your Auto Scaling group at a specific time, use the following as-put-scheduled-update-group-action command to create a scheduled action named ScaleDown that runs at the specified time (specified in "YYYY-MM-DDThh:mm:ssZ" format in UTC time):

as-put-scheduled-update-group-action ScaleDown --auto-scaling-group my-test-asg --start-time "2013-05-13T08:00:00Z" --desired-capacity 1 

To schedule scaling on a recurring schedule

You can specify a recurrence schedule using the Unix cron syntax format. For more information about cron syntax, see the Cron Wikipedia entry.

Use the following as-put-scheduled-update-group-action command to create a scheduled action named scaleup-schedule-year that runs at 00:30 hours on the first of January, June, and December each year:

as-put-scheduled-update-group-action  scaleup-schedule-year --auto-scaling-group my-test-asg --recurrence "30 0 1 1,6,12 0" --desired-capacity 3 

(Optional) Verify that the Auto Scaling Group is Scheduled for Scaling

Use the following as-describe-scheduled-actions command to list all the scheduled actions attached to your Auto Scaling groups that are still waiting to be executed. After a scheduled action is completed, it is automatically deleted and no longer visible in the list of planned actions.

as-describe-scheduled-actions --auto-scaling-group my-test-asg --headers

The following is an example response:

UPDATE-GROUP-ACTION  my-test-asg  ScaleUp   2013-05-12T08:00:00Z  3
UPDATE-GROUP-ACTION  my-test-asg  ScaleDown 2013-01-13T08:00:00Z  1

If the scheduled action is already executed, use as-describe-scaling-activities, with the --show-xml option, as follows:

as-describe-scaling-activities --auto-scaling-group my-test-asg --show-xml

The following is an example response. You can determine whether instances were launched due to a scheduled action by examining the description in the Cause field. Activities launched as a direct result of a scheduled action have a reference to the specific action name in Cause, as shown here.

<DescribeScalingActivitiesResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
  <DescribeScalingActivitiesResult>
    <NextToken>71382dd3-75af-4a57-9c23-988fdcb1866a</NextToken>
    <Activities>
      <member>
        <StatusCode>Successful</StatusCode>
        <Progress>100</Progress>
        <ActivityId>7d1a9dd2-7b53-4334-8a5f-5fa2a9731d64</ActivityId>
        <StartTime>2013-01-30T03:00:51.931Z</StartTime>
        <AutoScalingGroupName>my-test-asg</AutoScalingGroupName>
        <Cause>At 2013-01-30T03:00:21Z a scheduled action update of AutoScalingGroup constraints to min: 1, max: 5, desired: 3 
changing the desired capacity from 1 to 3.  At 2013-01-30T03:00:21Z the scheduled action ScaleUp executed. Setting desired capacity 
from 1 to 3.  At 2013-01-30T03:00:51Z an instance was started in response to a difference between desired and actual capacity, 
increasing the capacity from 1 to 3.</Cause>
        <Details>{}</Details>
        <Description>Launching a new EC2 instance: i-aacc62da</Description>
        <EndTime>2013-01-30T03:02:01Z</EndTime>
      </member>