Auto Scaling
Developer Guide (API Version 2011-01-01)
« 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.Did this page help you?  Yes | No |  Tell us about it...

Scheduled Scaling

Scaling based on a schedule allows you to scale your application in response to predictable load changes. Let’s say that 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 will be rejected with an error message noting the conflict.

Create Scheduled Actions

The following steps outline how to create a scheduled action to scale your Auto Scaling group.

  1. Create a launch configuration

  2. Create an Auto Scaling group

  3. Create a scheduled action to scale one time or on a recurring schedule

  4. Verify that your Auto Scaling group is scheduled for scaling

You can create scheduled actions using the Auto Scaling command line interface (CLI) or the Query API. If you are planning to use the CLI, be sure you have installed the tools. For more information, see Install the Auto Scaling Command Line Interface.

Using the Command Line Interface

Use the following Auto Scaling commands to create a launch configuration, create and describe Auto Scaling groups, and create and describe scheduled action.

CommandDescription

as-create-launch-config

Creates a new launch configuration with specified attributes.

as-create-auto-scaling-group

Creates a new Auto Scaling group with a specified name and other attributes.

as-describe-auto-scaling-groups

Describes the Auto Scaling groups, if the groups exist.

as-put-scheduled-update-group-action

Creates a scheduled action for an Auto Scaling group.

as-describe-scheduled-actions

Lists all the actions scheduled for your Auto Scaling group that have not been executed.

For more information about the command syntax of any of the commands listed above, use the --help option with the command or see the Auto Scaling Quick Reference Card.

For common conventions the documentation uses to represent command symbols, see Document Conventions.

Create a Launch Configuration

If you're not familiar with how to create a launch configuration or an Auto Scaling group, we recommend that you go through the steps in the Basic Scenario in Auto Scaling.

For this walkthrough, specify the following values for the as-create-launch-config command:

  • Launch configuration name = my-test-lc

  • Image ID = ami-514ac838

    If you don't have an AMI, and you want to find a suitable one, follow the instructions in Finding a Suitable AMI.

  • Instance type = m1.small

Your command should look similar to the following example:

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

If your request is successful, you should get a confirmation similar to the following example:

OK-Created launch config

Create an Auto Scaling Group

Create your Auto Scaling group by using the as-create-auto-scaling-group command by specifying the following values:

  • Auto Scaling group name = my-test-asg

  • Launch configuration name = my-test-lc

  • Availability Zone = us-east-1e

  • Max size = 5

  • Min size = 1

Your command should look similar to the following example:

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

If your request was successful, you should get a confirmation similar to the following example:

OK-Created AutoScalingGroup

Verify Your Auto Scaling Group

Use the as-describe-auto-scaling-groups command to verify your Auto Scaling group.

Your command should look similar to the following example:

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

Note

Specify the --headers general option to show column headers that will organize the describe command's information.

Auto Scaling responds with details about the group and the instances launched. The information you get should be similar to the following example:

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   
            

You can see that Auto Scaling launched an instance using the my-test-lc, it is running (InService) and is healthy.

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

  1. Use the as-put-scheduled-update-group-action with the following values:

    • Name of your scheduled action = ScaleOut

    • Auto Scaling group name = my-test-asg

    • Desired Capacity = 3

    • Start time = “2013-05-12T08:00:00Z”

      Note

      If you try to schedule your action in the past, Auto Scaling returns an error message.

      Auto Scaling supports the date and time expressed in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT only.

    Your command should look similar to the following example:

    as-put-scheduled-update-group-action ScaleUp --auto-scaling-group my-test-asg --start-time "2013-05-12T08:00:00Z" --desired-capacity 3
  2. You should get a confirmation similar to the following example:

    OK-Put Scheduled Update Group Action
  3. You might want to reduce the number of running instances in your Auto Scaling group to 1 after a certain time. Use as-put-scheduled-update-group-action by specifying a later date for changing the desired capacity to 1.

    • Name of your scheduled action = ScaleIn

    • Auto Scaling group name = my-test-asg

    • Desired Capacity = 1

    • Start time = “2013-05-13T08:00:00Z”

      Note

      If you try to schedule your action in the past, Auto Scaling returns an error message.

      Auto Scaling supports the date and time expressed in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT only.

    Your command should look similar to the following example:

    as-put-scheduled-update-group-action ScaleDown --auto-scaling-group my-test-asg --start-time "2013-05-13T08:00:00Z" --desired-capacity 1
  4. If your request was successful, you should get a confirmation similar to the following example:

    OK-Put Scheduled Update Group Action

To create scheduled actions for scaling on a recurring schedule

  1. The following example creates a scheduled action to scale on a recurring schedule that is scheduled to execute at 00:30 hours on the first of January, June, and December every year. To create a scheduled action based on recurring schedule, use the as-put-scheduled-update-group-action with the following parameters:

    • Name of your scheduled action = Scaleout-schedule-year

    • Auto Scaling group name = my-test-asg

    • Desired Capacity = 3

    • Recurrence = “30 0 1 1,6,12 0”

      Note

      If you try to schedule your action in the past, Auto Scaling returns an error message.

      You must specify the recurrence schedule using the Unix cron syntax format. For information about cron syntax, go to Wikipedia,.

    Your command should look similar to the following example:

    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
  2. If your request was successful, you should get a confirmation similar to the following example:

    OK-Put Scheduled Update Group Action

Verify that the Auto Scaling Group is Scheduled for Scaling

To verify that your Auto Scaling group is scheduled for scaling

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

    Your command should similar to the following example:

    as-describe-scheduled-actions  --auto-scaling-group my-test-asg  --headers
  2. The information you get should be similar to the following example:

    UPDATE-GROUP-ACTION  my-test-asg  ScaleOut  2013-05-12T08:00:00Z  3
    UPDATE-GROUP-ACTION  my-test-asg  ScaleIn 2013-01-13T08:00:00Z  1
    
  3. If the scheduled action is already executed, use as-describe-scaling-activities by specifying the name of your Auto Scaling group and using the --show-xml option.

    Your command should look similar to the following example:

    as-describe-scaling-activities  --auto-scaling-group my-test-asg  --show-xml
  4. The information you get should be similar to the following example.

    <DescribeScalingActivitiesResponse xmlns="http://autoscaling.amazonaws.com/doc/2
    011-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 fro
    m 1 to 3.  At 2013-01-30T03:00:21Z the scheduled action ScaleOut 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>

    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 will have a reference to the specific action name in the Cause field of the corresponding scaling activity. The Cause field in the example shows the scheduled action taken for the Auto Scaling group my-test-asg.

Congratulations! You have successfully created a scaling plan for your Auto Scaling group based either on a specific time or recurring schedule.

Using the Query API

Use the following Auto Scaling actions to create a launch configuration, create and describe Auto Scaling groups, and create and describe a scheduled action.

CommandDescription

CreateLaunchConfiguration

Creates a new launch configuration with specified attributes.

CreateAutoScalingGroup

Creates a new Auto Scaling group with a specified name and other attributes.

DescribeAutoScalingGroups

Describes the Auto Scaling groups, if the groups exist.

PutScheduledUpdateGroupAction

Creates a scheduled action for an Auto Scaling group..

DescribeScheduledActions

Lists all the actions scheduled for your Auto Scaling group that have not been executed.

For more information about Auto Scaling actions, see the Auto Scaling API Reference.

For common conventions the documentation uses to represent command symbols, see Document Conventions.

Create a Launch Configuration

If you're not familiar with how to create a launch configuration or an Auto Scaling group, we recommend that you go through the steps in the Basic Scenario in Auto Scaling.

For this walkthrough, specify the following parameters for the CreateLaunchConfiguration action:

  • LaunchConfiguration name = my-test-lc

  • ImageId = ami-514ac838

    If you don't have an AMI, and you want to find a suitable one, follow the instructions in Finding a Suitable AMI.

  • InstanceType = m1.small

If your request is successful, you should get a confirmation similar to the following example:

<CreateLaunchConfigurationResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
  <ResponseMetadata>
    <RequestId>7c6e177f-f082-11e1-ac58-3714bEXAMPLE</RequestId>
  </ResponseMetadata>
</CreateLaunchConfigurationResponse>

Create an Auto Scaling Group

Call the CreateAutoScalingGroup action to create your Auto Scaling group by specifying the following parameters:

  • AutoScalingGroupName = my-test-asg

  • LaunchConfigurationName = my-test-lc

  • AvailabilityZone.member.1 = us-east-1e

  • MaxSize = 5

  • MinSize = 1

If your request is successful, you should get confirmation similar to the following example:

<CreateAutoScalingGroupResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
  <ResponseMetadata>
    <RequestId>8d798a29-f083-11e1-bdfb-cb223EXAMPLE</RequestId>
  </ResponseMetadata>
</CreateAutoScalingGroupResponse>

Verify Your Auto Scaling Group

Call the DescribeAutoScalingGroups action with the following parameters to verify your Auto Scaling group.

  • AutoScalingGroupName = my-test-asg

If your request is successful, you should get response similar to the following example. The response shows the details about the group and the instances launched.

<DescribeAutoScalingGroupsResponse xmlns="http://autoscaling.amazonaws.com/doc/2
011-01-01/">
  <DescribeAutoScalingGroupsResult>
    <AutoScalingGroups>
      <member>
        <Tags/>
        <SuspendedProcesses/>
        <AutoScalingGroupName>my-test-asg</AutoScalingGroupName>
        <HealthCheckType>EC2</HealthCheckType>
        <CreatedTime>2013-01-22T23:58:48.718Z</CreatedTime>
        <EnabledMetrics/>
        <LaunchConfigurationName>my-test-lc</LaunchConfigurationName>
        <Instances>
          <member>
            <HealthStatus>Healthy</HealthStatus>
            <AvailabilityZone>us-east-1e</AvailabilityZone>
            <InstanceId>i-98e204e8</InstanceId>
            <LaunchConfigurationName>my-test-lc</LaunchConfigurationName>
            <LifecycleState>InService</LifecycleState>
          </member>
        </Instances>
        <DesiredCapacity>1</DesiredCapacity>
        <AvailabilityZones>
          <member>us-east-1e</member>
        </AvailabilityZones>
        <LoadBalancerNames/>
        <MinSize>1</MinSize>
        <VPCZoneIdentifier/>
        <HealthCheckGracePeriod>0</HealthCheckGracePeriod>
        <DefaultCooldown>300</DefaultCooldown>
        <AutoScalingGroupARN>arn:aws:autoscaling:us-east-1:123456789012:autoScal
ingGroup:66be2dec-ee0f-4178-8a3a-e13d91c4eba9:autoScalingGroupName/my-test-asg<
/AutoScalingGroupARN>
        <TerminationPolicies>
          <member>Default</member>
        </TerminationPolicies>
        <MaxSize>5</MaxSize>
      </member>
    </AutoScalingGroups>
  </DescribeAutoScalingGroupsResult>
  <ResponseMetadata>
    <RequestId>cb35382a-64ef-11e2-a7f1-9f203EXAMPLE</RequestId>
  </ResponseMetadata>
</DescribeAutoScalingGroupsResponse>            

You can see that Auto Scaling launched an instance using the my-test-lc launch configuration, it is running (InService) and it is healthy.

Create a Schedule for Scaling Actions

You can create a schedule for scaling on a specific date and time or for scaling based on a daily, weekly, monthly, or yearly schedule.

To schedule scaling on a specific date and time

  1. Call the PutScheduledUpdateGroupAction action using the following parameters:

    • ScheduledActionName = ScaleOut

    • AutoScalingGroupName = my-test-asg

    • DesiredCapacity = 3

    • StartTime = “2013-05-12T08:00:00Z”

      Note

      If you try to schedule your action in the past, Auto Scaling returns an error message.

      Auto Scaling supports the date and time expressed in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT only.

  2. If your request is successful, you should get a confirmation similar to the following example:

    <PutScheduledUpdateGroupActionResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
      <ResponseMetadata>
        <RequestId>757957fc-6a5f-11e2-bb90-e9977EXAMPLE</RequestId>
      </ResponseMetadata>
    </PutScheduledUpdateGroupActionResponse>
  3. You might want to reduce the number of running instances in your Auto Scaling group to 1 after a certain time. Call the PutScheduledUpdateGroupAction action using the following parameters:

    • ScheduledActionName = ScaleIn

    • AutoScalingGroupName = my-test-asg

    • DesiredCapacity = 1

    • StartTime = “2013-05-13T08:00:00Z”

      Note

      If you try to schedule your action in the past, Auto Scaling returns an error message.

      Auto Scaling supports the date and time expressed in "YYYY-MM-DDThh:mm:ssZ" format in UTC/GMT only.

  4. If your request is successful, you should get a confirmation similar to the following example:

    <PutScheduledUpdateGroupActionResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
      <ResponseMetadata>
        <RequestId>75cba157-6a60-11e2-a62c-b1235EXAMPLE</RequestId>
      </ResponseMetadata>
    </PutScheduledUpdateGroupActionResponse>

To create scheduled actions for scaling on recurrence basis

  1. The following example creates a scheduled action to scale on a recurring schedule that is scheduled to execute at 00:30 hours on the first of January, June, and December every year. To create a scheduled action based on recurring schedule, call PutScheduledUpdateGroupAction action with the following parameters:

    • ScheduledActionName = Scaleout-schedule-year

    • AutoScalingGroupName = my-test-asg

    • DesiredCapacity = 3

    • Recurrence = “30 0 1 1,6,12 0”

      Note

      If you try to schedule your action in the past, Auto Scaling returns an error message.

      You must specify Recurrence schedule using the Unix cron syntax format. For information about cron syntax, go to Wikipedia.

  2. If your request is successful, you should get a confirmation similar to the following example:

    <PutScheduledUpdateGroupActionResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
      <ResponseMetadata>
        <RequestId>3bc8c9bc-6a62-11e2-8a51-4b8a1EXAMPLE</RequestId>
      </ResponseMetadata>
    </PutScheduledUpdateGroupActionResponse>

Verify that Your Auto Scaling Group is Scheduled for Scaling

To verify that your Auto Scaling group is scheduled for scaling

  1. Call the DescribeScheduledActions action to list all the scheduled actions attached to your Auto Scaling groups that are still waiting to be executed. Once a scheduled action is completed, it is automatically deleted and, thus, no longer visible in the list of planned actions. Use the following parameter to narrow down the result to your Auto Scaling group:

    • AutoScalingGroupName = my-test-asg

    The response lists all the actions scheduled for your Auto Scaling group.

  2. If the scheduled action is already executed, use DescribeScalingActivities by specifying the name of your Auto Scaling group.

  3. If your request is successful, you should get response similar to the following example. The response shows details about all the scaling activities for your Auto Scaling group.

    <DescribeScalingActivitiesResponse xmlns="http://autoscaling.amazonaws.com/doc/2
    011-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 fro
    m 1 to 3.  At 2013-01-30T03:00:21Z the scheduled action ScaleOut 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>

    You can determine if 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 will have a reference to the specific action name in the Cause field of the corresponding scaling activity. The Cause field in the example shows the scheduled action taken for the Auto Scaling group my-test-asg.

Congratulations! You have successfully created a scaling plan for your Auto Scaling group based on either a specific time or a recurring schedule.