AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-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...

Configuring Auto Scaling with AWS Elastic Beanstalk

Auto Scaling is a web service designed to automatically launch or terminate Amazon EC2 instances based on user-defined triggers. Users can set up Auto Scaling groups and associate triggers with these groups to automatically scale computing resources based on metrics such as bandwidth usage or CPU utilization. Auto Scaling works with Amazon CloudWatch to retrieve metrics for the server instances running your application.

Auto Scaling lets you take a group of Amazon EC2 instances and set various parameters to have this group automatically increase or decrease in number. Auto Scaling can add or remove Amazon EC2 instances from that group to help you seamlessly deal with traffic changes to 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.

AWS Management Console

AWS Elastic Beanstalk provisions Auto Scaling for your application. You can configure how Auto Scaling behaves by clicking the Auto Scaling tab in the Edit Configuration window.

AWS 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 to control how your AWS 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 AWS Elastic Beanstalk application uses.

AWS Elastic Beanstalk Auto Scaling Launch Config Configuration Window

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 you want AWS Elastic Beanstalk to launch your instances in. It is recommended that you choose enough Availability Zones to spread your instances across. 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 Availabilty Zones you want AWS Elastic Beanstalk to launch instance(s) in across a region. If you do not select any custom Availability Zones, then AWS 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

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.

Note

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 Reserved Instances.

Triggers

A trigger is an Auto Scaling mechanism that you set to tell the system when you want to increase (scale out) the number of instances, and when you want to decrease (scale in) the number of instances. You can configure triggers to fire on any metric published to Amazon CloudWatch, such as CPU utilization, and determine if the conditions you specified have been met. When the upper or lower thresholds of the conditions you have specified for the metric have been breached for the specified period of time, the trigger launches a long-running process called a Scaling Activity.

You can define a scaling trigger for your AWS Elastic Beanstalk application using the AWS Management Console.

AWS Elastic Beanstalk Auto Scaling Trigger

Auto Scaling triggers work by watching a specific Amazon CloudWatch metric for an instance. Triggers include CPU utilization, network traffic, and disk activity. Use the Trigger Measurement drop-down list to select a metric for your trigger.

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

  • You can use specify which statistic the trigger should use. You can select Minimum, Maximum, Sum, or Average using the Trigger Statistic drop-down list.

  • Specify the unit for the trigger measurement using the Unit of Measurement drop-down list.

  • The value in the Measurement Period box specifies how frequently Amazon CloudWatch measures the metrics for your trigger. The Breach Duration is the amount of time a metric can be beyond its defined limit (as specified in the Upper Threshold and Lower Threshold boxes) before the trigger fires.

  • The Upper Breach Scale Increment and Lower Breach Scale Increment boxes specify how many Amazon EC2 instances to add or remove when performing a scaling activity.

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

CLI

To edit an application's environment settings

  • Update an application's environment settings.

    PROMPT> elastic-beanstalk-update-environment -e MySampleAppEnv -f "Options.txt"

Options.txt

[
{"Namespace": "aws:autoscaling:asg",
"OptionName": "MinSize",
"Value": "1"},
{"Namespace": "aws:autoscaling:asg",
"OptionName": "MaxSize",
"Value": "4"},
{"Namespace": "aws:autoscaling:asg",
"OptionName": "Availability Zones",
"Value": "Any 1"},
{"Namespace": "aws:autoscaling:asg",
"OptionName": "Cooldown",
"Value": "360"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "MeasureName",
"Value": "NetworkOut"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "Statistic",
"Value": "Average"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "Unit",
"Value": "Bytes"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "Period",
"Value": "5"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "BreachDuration",
"Value": "5"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "UpperThreshold",
"Value": "6000000"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "UpperBreachScaleIncrement",
"Value": "1"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "LowerThreshold",
"Value": "2000000"},
{"Namespace": "aws:autoscaling:trigger",
"OptionName": "LowerBreachScaleIncrement",
"Value": "-1"}
]

You can also specify custom Availability Zones using the CLI.

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

  • Update an application's environment settings.

    PROMPT> elastic-beanstalk-update-environment -e MySampleAppEnv -f "Options.txt"

Options.txt

[
  {"Namespace": "aws:autoscaling:asg",
   "OptionName": "MinSize",
   "Value": "1"},
   {"Namespace": "aws:autoscaling:asg",
   "OptionName": "MaxSize",
   "Value": "4"},
  {"Namespace": "aws:autoscaling:asg",
   "OptionName": "Availability Zones",
   "Value": "Any 1"},
   {"Namespace": "aws:autoscaling:asg",
   "OptionName": "Cooldown",
   "Value": "360"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "MeasureName",
   "Value": "NetworkOut"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "Statistic",
   "Value": "Average"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "Unit",
   "Value": "Bytes"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "Period",
   "Value": "5"},
    {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "BreachDuration",
   "Value": "5"},
    {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "UpperThreshold",
   "Value": "6000000"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "UpperBreachScaleIncrement",
   "Value": "1"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "LowerThreshold",
   "Value": "2000000"},
   {"Namespace": "aws:autoscaling:trigger",
   "OptionName": "LowerBreachScaleIncrement",
   "Value": "-1"}
   ]

You can also specify custom Availability Zones using the CLI.

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

  • Update an application's environment settings.

    PROMPT> elastic-beanstalk-update-environment -e MySampleAppEnv -f "Options.txt"

Options.txt

[
  {"Namespace": "aws:autoscaling:asg",
   "OptionName": "Custom Availability Zones",
   "Value": "us-east-1b, us-east-1c"}
]

Note

You use the command elastic-beanstalk-update-environment 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-year or three-year term, and pay a significantly lower hourly rate for that instance. For more information about Reserved Instances, go to Reserved Instances in the Amazon Elastic Compute Cloud User Guide.

API

To edit an application's environment settings

  • Call UpdateEnvironment with the following parameters:

    • EnvironmentName = SampleAppEnv

    • OptionSettings.member.1.Namespace = aws:autoscaling:asg

    • OptionSettings.member.1.OptionName = MinSize

    • OptionSettings.member.1.Value = 1

    • OptionSettings.member.2.Namespace = aws:autoscaling:asg

    • OptionSettings.member.2.OptionName = MaxSize

    • OptionSettings.member.2.Value = 4

    • OptionSettings.member.3.Namespace = aws:autoscaling:asg

    • OptionSettings.member.3.OptionName = Availability Zones

    • OptionSettings.member.3.Value = Any 1

    • OptionSettings.member.4.Namespace = aws:autoscaling:asg

    • OptionSettings.member.4.OptionName = Cooldown

    • OptionSettings.member.4.Value = 360

    • OptionSettings.member.5.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.5.OptionName = MeasureName

    • OptionSettings.member.5.Value = NetworkOut

    • OptionSettings.member.6.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.6.OptionName = Statistic

    • OptionSettings.member.6.Value = Average

    • OptionSettings.member.7.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.7.OptionName = Unit

    • OptionSettings.member.7.Value = Bytes

    • OptionSettings.member.8.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.8.OptionName = Period

    • OptionSettings.member.8.Value = 5

    • OptionSettings.member.9.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.9.OptionName = BreachDuration

    • OptionSettings.member.9.Value = 5

    • OptionSettings.member.10.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.10.OptionName = UpperThreshold

    • OptionSettings.member.10.Value = 6000000

    • OptionSettings.member.11.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.11.OptionName = UpperBreachScaleIncrement

    • OptionSettings.member.11.Value = 1

    • OptionSettings.member.12.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.12.OptionName = LowerThreshold

    • OptionSettings.member.12.Value = 2000000

    • OptionSettings.member.13.Namespace = aws:autoscaling:trigger

    • OptionSettings.member.13.OptionName = LowerBreachScaleIncrement

    • OptionSettings.member.13.Value = -1

    Example

    https://elasticbeanstalk.us-east-1.amazon.com/?EnvironmentName=SampleAppEnv
    &OptionSettings.member.1.Namespace=aws%3Aautoscaling%3Aasg
    &OptionSettings.member.1.OptionName=MinSize
    &OptionSettings.member.1.Value=1
    &OptionSettings.member.2.Namespace=aws%3Aautoscaling%3Aasg
    &OptionSettings.member.2.OptionName=MaxSize
    &OptionSettings.member.2.Value=4
    &OptionSettings.member.3.Namespace=aws%3Aautoscaling%3Aasg
    &OptionSettings.member.3.OptionName=Availability%20Zones
    &OptionSettings.member.3.Value=Any%201
    &OptionSettings.member.4.Namespace=aws%3Aautoscaling%3Aasg
    &OptionSettings.member.4.OptionName=Cooldown
    &OptionSettings.member.4.Value=360
    &OptionSettings.member.5.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.5.OptionName=MeasureName
    &OptionSettings.member.5.Value=NetworkOut
    &OptionSettings.member.6.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.6.OptionName=Statistic
    &OptionSettings.member.6.Value=Average
    &OptionSettings.member.7.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.7.OptionName=Unit
    &OptionSettings.member.7.Value=Bytes
    &OptionSettings.member.8.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.8.OptionName=Period
    &OptionSettings.member.8.Value=5
    &OptionSettings.member.9.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.9.OptionName=BreachDuration
    &OptionSettings.member.9.Value=5
    &OptionSettings.member.10.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.10.OptionName=UpperThreshold
    &OptionSettings.member.10.Value=6000000
    &OptionSettings.member.11.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.11.OptionName=UpperBreachScaleIncrement
    &OptionSettings.member.11.Value=1
    &OptionSettings.member.12.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.12.OptionName=LowerThreshold
    &OptionSettings.member.12.Value=2000000
    &OptionSettings.member.13.Namespace=aws%3Aautoscaling%3Atrigger
    &OptionSettings.member.13.OptionName=Period
    &OptionSettings.member.13.Value=-1
    &Operation=UpdateEnvironment
    &AuthParams          

You can also specify custom Availability Zones using the API.

  • Call UpdateEnvironment with the following parameters:

    • EnvironmentName = SampleAppEnv

    • OptionSettings.member.1.Namespace = aws:autoscaling:asg

    • OptionSettings.member.1.OptionName = Custom Availability Zones

    • OptionSettings.member.1.Value = us-east-1b, us-east-1c

    Example

    https://elasticbeanstalk.us-east-1.amazon.com/?EnvironmentName=SampleAppEnv
    &OptionSettings.member.1.Namespace=aws%3Aautoscaling%3Aasg
    &OptionSettings.member.1.OptionName=Custom%20Availability%20Zones
    &OptionSettings.member.1.Value=us-east-1b%2C%20us-east-1c
    &Operation=UpdateEnvironment
    &AuthParams