Auto Scaling group configuration for your Elastic Beanstalk environment - AWS Elastic Beanstalk

Auto Scaling group configuration for your Elastic Beanstalk environment

This topic describes the different approaches to configure Auto Scaling for your Elastic Beanstalk environment. You can use the Elastic Beanstalk console, the EB CLI, or namespace options.

Important

The EnableSpot option setting can cause Elastic Beanstalk to create an environment with a launch template or update an existing environment from launch configurations to launch templates. For more information, see Launch Templates.

Auto Scaling group configuration using the Elastic Beanstalk console

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

To configure the Auto Scaling group in the Elastic Beanstalk console
  1. Open the Elastic Beanstalk console, and in the Regions list, select your AWS Region.

  2. In the navigation pane, choose Environments, and then choose the name of your environment from the list.

    Note

    If you have many environments, use the search bar to filter the environment list.

  3. In the navigation pane, choose Configuration.

  4. In the Capacity configuration category, choose Edit.

  5. In the Auto Scaling group section, configure the following settings.

    • Environment type – Select Load balanced.

    • Min instances – The minimum number of EC2 instances that the group should contain at any time. The group starts with the minimum count and adds instances when the scale-up trigger condition is met.

    • Max instances – The maximum number of EC2 instances that the group should contain at any time.

      Note

      If you use rolling updates, be sure that the maximum instance count is higher than the Minimum instances in service setting for rolling updates.

    • Fleet composition – The default is On-Demand Instances. To enable Spot Instance requests, select Combined purchase options and instances.

      Important

      The EnableSpot option setting can cause Elastic Beanstalk to create an environment with a launch template or update an existing environment from launch configurations to launch templates. For more information, see Launch Templates.

      The following options are enabled if you select to enable Spot Instance requests:

      • Maximum spot price – For recommendations about maximum price options for Spot Instances, see Spot Instance pricing history in the Amazon EC2 User Guide.

      • On-Demand base – The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales out.

      • On-Demand above base – The percentage of On-Demand Instances as part of any additional capacity that your Auto Scaling group provisions beyond the On-Demand base instances.

        Note

        The options On-Demand base and On-Demand above base correlate to the Min and Max Instances options listed earlier. For more information about these options and examples, see Spot instance support.

      • Enable Capacity Rebalancing – This option is only relevant when there is at least one Spot Instance in your Auto Scaling group. When this feature is enabled, EC2 automatically attempts to replace Spot Instances in the Auto Scaling group before they are interrupted, minimizing Spot Instance interruptions to your applications. For more information, see Capacity Rebalancing in the Amazon EC2 Auto Scaling User Guide.

    • Instance type – The type of Amazon EC2 instance launched to run your application. For details, see Instance types.

    • AMI ID – The machine image that Elastic Beanstalk uses to launch Amazon EC2 instances in your environment. For details, see AMI ID.

    • Availability Zones – Choose the number of Availability Zones to spread your environment's instances across. By default, the Auto Scaling group launches instances evenly across all usable zones. To concentrate your instances in fewer zones, choose the number of zones to use. For production environments, use at least two zones to ensure that your application is available in case one Availability Zone goes out.

    • Placement (optional) – Choose the Availability Zones to use. Use this setting if your instances need to connect to resources in specific zones, or if you have purchased reserved instances, which are zone-specific. If you launch your environment in a custom VPC, you cannot configure this option. In a custom VPC, you choose Availability Zones for the subnets that you assign to your environment.

    • Scaling cooldown – The amount of time, in seconds, to wait for instances to launch or terminate after scaling, before continuing to evaluate triggers. For more information, see Scaling Cooldowns.

    Elastic Beanstalk Auto Scaling configuration window
  6. To save the changes choose Apply at the bottom of the page.

Auto Scaling group configuration using the EB CLI

When creating an environment using the eb create command, you can specify a few options that are related to your environment's Auto Scaling group. These are some of the options that help you control the capacity of your environment.

--single

Creates the environment with one Amazon EC2 instance and no load balancer. If you don't use this option, a load-balancer is added to the environment that's created.

--enable-spot

Enables Spot Instance requests for your environment.

Important

The enable-spot option setting can cause Elastic Beanstalk to create an environment with a launch template or update an existing environment from launch configurations to launch templates. For more information, see Launch Templates.

The following options for the eb create command can only be used with --enable-spot.

--instance-types

Lists the Amazon EC2 instance types that you want your environment to use.

--spot-max-price

The maximum price per unit hour, in US dollars, that you're willing to pay for a Spot Instance. For recommendations about maximum price options for Spot Instances, see Spot Instance pricing history in the Amazon EC2 User Guide.

--on-demand-base-capacity

The minimum number of On-Demand Instances that your Auto Scaling group provisions before considering Spot Instances as your environment scales up.

--on-demand-above-base-capacity

The percentage of On-Demand Instances as part of additional capacity that your Auto Scaling group provisions that's more than the number of instances that's specified by the --on-demand-base-capacity option.

The following example creates an environment and configures the Auto Scaling group to enable Spot Instance requests for the new environment. For this example, three possible instance types can be used.

$ eb create --enable-spot --instance-types "t2.micro,t3.micro,t3.small"
Important

There is another similarly named option that's called --instance-type (no “s”) that the EB CLI only recognizes when processing On-Demand Instances. Don't use --instance-type (no "s") with the --enable-spot option. If you do, the EB CLI ignores it. Instead use --instance-types (with "s") with the --enable-spot option.

Namespace configuration options

Elastic Beanstalk provides configuration options for Auto Scaling settings in two namespaces: aws:autoscaling:asg and aws:ec2:instances.

The aws:autoscaling:asg namespace

The aws:autoscaling:asg namespace provides options for overall scale and availability.

The following configuration file example configures the Auto Scaling group to use two to four instances, specific availability zones, and a cooldown period of 12 minutes (720 seconds). Capacity Rebalancing for Spot Instances is enabled. This last option only takes effect if EnableSpot is set to true in the aws:ec2:instances namespace, as shown in the configuration file example following this one.

option_settings: aws:autoscaling:asg: Availability Zones: Any Cooldown: '720' Custom Availability Zones: 'us-west-2a,us-west-2b' MaxSize: '4' MinSize: '2' EnableCapacityRebalancing: true

The aws:ec2:instances namespace

The aws:ec2:instances namespace provides options related to your environment's instances, including Spot Instance management. It complements aws:autoscaling:launchconfiguration and aws:autoscaling:asg.

When you update your environment configuration and remove one or more instance types from the InstanceTypes option, Elastic Beanstalk terminates any Amazon EC2 instances running on any of the removed instance types. Your environment's Auto Scaling group then launches new instances, as necessary to complete the desired capacity, using your current specified instance types.

The following configuration file example configures the Auto Scaling group to enable Spot Instance requests for your environment. Three possible instance types can be used. At least one On-Demand Instance is used for baseline capacity, and a sustained 33% of On-Demand Instances is used for any additional capacity.

option_settings: aws:ec2:instances: EnableSpot: true InstanceTypes: 't2.micro,t3.micro,t3.small' SpotFleetOnDemandBase: '1' SpotFleetOnDemandAboveBasePercentage: '33'

To choose Spot Instance types, use the Spot Instance Advisor.

Important

The EnableSpot option setting can cause Elastic Beanstalk to create an environment with a launch template or update an existing environment from launch configurations to launch templates. For more information, see Launch Templates.