AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Configuring Auto Scaling with Elastic Beanstalk

Auto Scaling is a web service designed to automatically launch or terminate Amazon EC2 instances in an autoscaling group based on parameters that you define. Elastic Beanstalk supports Auto Scaling for load-balancing, autoscaling environments. Automatically increasing or decreasing the number of Amazon EC2 instances helps you seamlessly deal with traffic changes to your application. The triggers that you define for an autoscaling group instruct Elastic Beanstalk to scale computing resources in response to metrics such as bandwidth usage or CPU utilization. You can also schedule scaling actions to occur at specific times. Auto Scaling works with Amazon CloudWatch to retrieve metrics for the server instances running your application.

Auto Scaling also monitors the health of each Amazon EC2 instance that it launches. If any instance terminates unexpectedly, Auto Scaling detects the termination and launches a replacement instance. This capability enables you to maintain a fixed, desired number of Amazon EC2 instances automatically.

Note

Autoscaling settings can impact rolling updates. If you configured rolling updates, a rolling update cannot happen if the minimum number of instances in service for rolling updates is larger than the maximum size of the autoscaling group. You must change the value of either the Minimum instances in service setting for rolling updates or the Maximum instance count setting for the autoscaling group.

For more information about Auto Scaling, go to the Auto Scaling documentation.

AWS Management Console

You can configure how Auto Scaling works by editing Scaling on the environment's Configuration page in the environment management console.


          Elastic Beanstalk Auto Scaling Configuration Window

The following section discusses how to configure Auto Scaling parameters for your application.

Launch Configuration

You can edit the launch configuration in the Auto Scaling section of the page to control how your Elastic Beanstalk application provisions Auto Scaling resources.

The Minimum instance count and Maximum instance count boxes let you specify the minimum and maximum size of the Auto Scaling group that your Elastic Beanstalk application uses.

Note

To maintain a fixed number of Amazon EC2 instances, set the Minimum instance count and Maximum instance count boxes to the same value.

The Availability Zones box lets you specify the number of Availability Zones in which you want Elastic Beanstalk to launch instances. We recommend that you choose multiple Availability Zones so that instances can be launched in another Availability Zone if one zone becomes unavailable. For example, if you have a minimum of 3 instances, then you should choose 3 Availability Zones.

The Custom Availability Zones box lets you specify which Availability Zones you want Elastic Beanstalk to launch instance(s) in across a region. If you do not select any custom Availability Zones, then Elastic Beanstalk will choose the Availability Zones for you. The number of Availability Zones must be less than or equal to the number of custom Availability Zones you select. For example, if you select Any 2, then you must select at least two custom Availability Zones.

Note

Here are some things to keep in mind when working with Availability Zones:

  • It is important to launch instances in more than one Availability Zone in order to build fault-tolerant applications. If one Availability Zone goes down, your instances will still be running in another Availability Zones.

  • If you purchased Reserved Instances, you need to specify the same Availability Zone(s) that you specified when you purchased your Reserved Instances. Reserved Instances let you make a low, one-time, upfront payment for an instance, reserve it for a one- or three-year term, and pay a significantly lower hourly rate for that instance. For more information about Reserved Instances, see Reserved Instances in the Amazon EC2 User Guide for Linux Instances.

  • You can create custom Availability Zones only in a default VPC or non-VPC environment.

The Scaling cooldown (seconds) box specifies how long Auto Scaling will wait before resuming any scaling activities after it launches an instance so that the new instance has time to begin handling traffic. If, by the time the cooldown period elapses, your environment has the appropriate level of resources to keep the CloudWatch alarm from continuing to fire, then no new instances will be launched.

Triggers

You can edit the Scaling Trigger section of the page to set metrics-based parameters for scaling actions for your Elastic Beanstalk application. A trigger is an Auto Scaling mechanism that you define to tell the system when to increase (scale out) the number of instances and when to decrease (scale in) the number of instances. You can configure triggers to fire on Amazon EC2 or Elastic Load Balancing metrics published to Amazon CloudWatch, such as an Amazon EC2 instance's CPU utilization, and determine whether the conditions you specified have been met. When the upper or lower thresholds of the conditions for the metric have been breached for the specified period of time, the trigger launches a long-running process called a scaling activity. For more information about Amazon EC2 metrics, see Amazon Elastic Compute Cloud Dimensions and Metrics in the Amazon CloudWatch User Guide. For more information about Elastic Load Balancing metrics, see Monitor Your Load Balancer Using Amazon CloudWatch in the Elastic Load Balancing User Guide.

Auto Scaling triggers work by watching a specific Amazon CloudWatch metric for an instance. Triggers include CPU utilization, network traffic, disk activity, and instance health. Use the Trigger measurement setting to specify a metric for your trigger.

The following list describes the trigger parameters you can configure using the AWS Management Console.

  • Use Trigger statistic to specify which statistic the trigger should use—Minimum, Maximum, Sum, or Average.

  • Use Unit of measurement to specify the unit for the trigger measurement.

  • For Measurement period, specify how frequently Amazon CloudWatch measures the metrics for your trigger. Breach duration is the amount of time a metric can extend beyond its defined limit (as specified for Upper threshold and Lower threshold) before the trigger fires.

  • Upper breach scale increment and Lower breach scale increment specify how many Amazon EC2 instances to add or remove when performing a scaling activity.

Time-based Scaling

Time-based scaling enables you to plan scaling actions that launch or terminate Amazon EC2 instances in each autoscaling group. You can schedule scaling actions, as needed. To see the list of an environment's scheduled scaling actions, including expired ones, see the Time-based Scaling section of the Scaling page in the AWS Management Console. An environment can have up to 120 scheduled scaling actions, not including expired actions (actions that ended in the past).

If your Elastic Beanstalk application has predictable needs for scaling out or scaling in at specific times, you can schedule scaling actions on a recurring basis. You can also schedule a scaling action for a planned one-time future event. Instead of creating an entirely new scheduled action, you can reuse an expired scheduled action by changing the start time to a time and date in the future. (Elastic Beanstalk keeps a history of the most recent 150 expired scheduled actions.)

The table in the Time-based Scaling section displays the following information.

  • The Name column shows the name that you assigned the scheduled action when you created it. You cannot change the name of a scaling action after you create it.

  • The Limits column displays the minimum, maximum, and desired number of instances that you specified for the autoscaling group when you created or most recently changed the scheduled action.

  • In the Next occurrence column, you can see the next time the scheduled action will take effect. For a recurrent scaling action, the next occurrence is based on the recurrence that you specified with a CRON expression.

In the Time-based Scaling section of the page, if you click Add scheduled action, the New scheduled action window displays the following options:


            Elastic Beanstalk New Scheduled Scaling Action Window
  • Use Name to specify a name for the scheduled scaling action that differentiates it from other scaling actions and that you can use to find it later. You must use alphanumeric characters with no spaces. The name has a limit of 255 characters.

  • For Instances, indicate the Min (minimum) and Max (maximum) number of instances for the autoscaling group.

  • The Desired capacity box lets you specify the number of instances that you want running in the autoscaling group. The desired capacity must be less than or equal to the value you defined as the maximum number of instances and larger than or equal to the value you defined as the minimum.

  • For Occurrence, choose whether the scaling action should occur only once or on a recurring basis.

    • If you choose One-time, configure the following settings:

      • Start time – Specify a date and time in the future to run the action.

    • If you choose Recurrent, configure the following settings:

      • Recurrence – Use a CRON expression to specify the frequency with which you want the scheduled action to occur. For example, if you want to schedule a recurrent action that take effect every Tuesday at 6:30 PM UTC, you can use the CRON expression “30 6 * * 2”. For more information about CRON syntax, see Cron.

      • Start time (optional) – Specify a date and time in the future to activate the scheduled action. If you don't specify a start time, the scheduled action is active immediately. The console automatically selects the top of the next hour by default.

      • End time (optional) – Specify a date and time in the future when you want to stop the scheduled action. If you don’t specify an end time, the scaling action recurs until you configure it with an end date and time.

Use ISO 8601 time format to specify start and end times in UTC. For example, 2015-04-28T04:07:02Z. For more information about ISO 8601 time format, go to Date and Time Formats. The dates must be unique across all scheduled actions.

You can’t suspend a scheduled action using the Elastic Beanstalk management console, but you can configure option settings with the EB CLI to do so. When you suspend a scheduled scaling action, Elastic Beanstalk ignores the scheduled action and does nothing. Suspending an action lets you stop the scheduled action without deleting it so that you can resume the action later, if necessary.

Examples of Time-based Scaling Option Settings Files

This section provides examples of option settings files that will configure scheduled scaling actions. You include these files in the .ebextensions directory in your application source bundle. For more information about deploying configuration files with your application, see Advanced Environment Customization with Configuration Files (.ebextensions).

The following JSON snippet instructs Elastic Beanstalk to scale out from five instances to 10 instances at 2015-12-12T00:00:00Z.

[
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleUpSpecificTime",
        "OptionName": "MinSize",
        "Value": "5"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleUpSpecificTime",
        "OptionName": "MaxSize",
        "Value": "10"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleUpSpecificTime",
        "OptionName": "DesiredCapacity",
        "Value": "5"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleUpSpecificTime",
        "OptionName": "StartTime",
        "Value": "2015-12-12T00:00:00Z"
    }
]

The following JSON snippet instructs Elastic Beanstalk to scale in at 2015-12-12T07:00:00Z.

[
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleDownSpecificTime",
        "OptionName": "MinSize",
        "Value": "1"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleDownSpecificTime",
        "OptionName": "MaxSize",
        "Value": "1"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleDownSpecificTime",
        "OptionName": "DesiredCapacity",
        "Value": "4"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledScaleDownSpecificTime",
        "OptionName": "StartTime",
        "Value": "2015-12-12T07:00:00Z"
    }
]

The following JSON snippet instructs Elastic Beanstalk to scale out every day at 9AM. The action is scheduled to begin May 14, 2015 and end January 12, 2016.

[
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledPeriodicScaleup",
        "OptionName": "MinSize",
        "Value": "5"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledPeriodicScaleup",
        "OptionName": "MaxSize",
        "Value": "10"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledPeriodicScaleup",
        "OptionName": "DesiredCapacity",
        "Value": "5"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledPeriodicScaleup",
        "OptionName": "StartTime",
        "Value": "2015-05-14T07:00:00Z"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledPeriodicScaleup",
        "OptionName": "EndTime",
        "Value": "2016-01-12T07:00:00Z"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledPeriodicScaleup",
        "OptionName": "Recurrence",
        "Value": "0 9 * * *"
    }
]

The following JSON snippet instructs Elastic Beanstalk to scale in every Friday at 6PM. If you know that your application doesn’t receive as much traffic over the weekend, you can create a similar scheduled action.

[
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledWeekendScaleDown",
        "OptionName": "MinSize",
        "Value": "1"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledWeekendScaleDown",
        "OptionName": "MaxSize",
        "Value": "4"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledWeekendScaleDown",
        "OptionName": "DesiredCapacity",
        "Value": "1"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledWeekendScaleDown",
        "OptionName": "StartTime",
        "Value": "2015-12-12T07:00:00Z"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledWeekendScaleDown",
        "OptionName": "EndTime",
        "Value": "2016-01-12T07:00:00Z"
    },
    {
        "Namespace": "aws:autoscaling:scheduledaction",
        "ResourceName": "ScheduledWeekendScaleDown",
        "OptionName": "Recurrence",
        "Value": "0 18 * * 5"
    }
]

Command Line Interface (CLI)

You can use the EB CLI to edit the environment settings for autoscaling.

To edit an application's environment settings using EB CLI

  1. Update an application's environment settings.

    $ eb config my-env
  2. Add the following to the option settings file that opens in your text editor.

      AWSEBAutoScalingScaleDownPolicy.aws:autoscaling:trigger:
        LowerBreachScaleIncrement: '-1'
      AWSEBAutoScalingScaleUpPolicy.aws:autoscaling:trigger:
        UpperBreachScaleIncrement: '1'
      AWSEBCloudwatchAlarmHigh.aws:autoscaling:trigger:
        UpperThreshold: '6000000'
      AWSEBCloudwatchAlarmLow.aws:autoscaling:trigger:
        BreachDuration: '5'
        EvaluationPeriods: '1'
        LowerThreshold: '2000000'
        MeasureName: NetworkOut
        Period: '5'
        Statistic: Average
        Unit: Bytes
      aws:autoscaling:asg:
        Availability Zones: Any
        Cooldown: '360'
        Custom Availability Zones: null
        MaxSize: '4'
        MinSize: '1'
      aws:autoscaling:launchconfiguration:
        BlockDeviceMappings: null
        EC2KeyName: null
        IamInstanceProfile: aws-elasticbeanstalk-ec2-role
        ImageId: ami-13de5b0e
        InstanceType: t1.micro
        MonitoringInterval: 5 minute
        RootVolumeIOPS: null
        RootVolumeSize: null
        RootVolumeType: null
        SSHSourceRestriction: tcp,22,22,0.0.0.0/0
        SecurityGroups: awseb-e-um3yfrzq22-stack-AWSEBSecurityGroup-10MV688E4994W

You can also specify custom Availability Zones using EB CLI.

To update an application's environment settings with custom Availability Zones using EB CLI

  1. Update an application's environment settings with custom Availability Zones for autoscaling.

    $ eb config
  2. Add the following to the option settings file that opens in your text editor.

      aws:autoscaling:asg:
        Availability Zones: Any
        Cooldown: '360'
        Custom Availability Zones: 'us-west-2a,us-west-2b'
        MaxSize: '4'
        MinSize: '1'

You can use EB CLI to create a scheduled action to scale out or scale in the number of instances in each autoscaling group in your environment.

To create a new scheduled scaling action using EB CLI

  1. Run eb config

    $ eb config
  2. Add the following to the option settings file that opens in your text editor to create a one-time scheduled scaling action.

    Note

    In the following examples, ScheduledScaleUpSpecificTime and ScheduledScaleUpRecurring are the names you want to give each respective scheduled action. Settings are grouped according to the scheduled scaling action name.

      ScheduledScaleUpSpecificTime.aws:autoscaling:scheduledaction:
        DesiredCapacity: '5'
        EndTime: null
        MaxSize: '10'
        MinSize: '5'
        Recurrence: null
        StartTime: '2015-12-12T00:00:00Z'
        Suspend: 'false'

    Add the following to the option settings file that opens in your text editor to create a recurring scheduled scaling action.

      ScheduledScaleUpRecurring.aws:autoscaling:scheduledaction:
        DesiredCapacity: '5'
        EndTime: '2016-01-12T07:00:00Z'
        MaxSize: '10'
        MinSize: '5'
        Recurrence: '0 9 * * *'
        StartTime: '2015-12-12T00:00:00Z'
        Suspend: 'false'
    

The EB CLI and Elastic Beanstalk console apply recommended values for the preceding options. These settings must be removed if you want to use configuration files to configure the same. See Recommended Values for details.