Spot instance support - AWS Elastic Beanstalk

Spot instance support

To take advantage of Amazon EC2 Spot Instances, you can enable a Spot option for your environment. Your environment's Auto Scaling group then combines Amazon EC2 purchase options and maintains a mix of On-Demand and Spot Instances.

Note

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.

This topic describes the following methods to enable Spot Instance requests for your environment:

Important

Demand for Spot Instances can vary significantly from moment to moment, and the availability of Spot Instances can also vary significantly depending on how many unused Amazon EC2 instances are available. It's always possible that your Spot Instance might be interrupted.

To help minimize the impact of these interruptions to your application, you can enable the Capacity Rebalancing option included with Amazon EC2 Auto Scaling. With this feature enabled, EC2 automatically attempts to replace Spot Instances in an Auto Scaling group before they are interrupted. To enable this feature use the Elastic Beanstalk console to configure the Auto Scaling group. Alternatively, you can set the Elastic Beanstalk EnableCapacityRebalancing configuration option to true in the aws:autoscaling:asg namespace.

For more information, see Capacity Rebalancing in the Amazon EC2 Auto Scaling User Guide and Spot Instance Interruptions in the Amazon EC2 User Guide.

Elastic Beanstalk provides several configuration options to support the Spot feature. They're discussed in the following sections that explain configuration of your Auto Scaling group.

Two of these options, in the aws:ec2:instances namespace, deserve special attention:

  • SpotFleetOnDemandBase

  • SpotFleetOnDemandAboveBasePercentage

These two options correlate with the MinSize option in the aws:autoscaling:asg namespace:

  • Only MinSize determines your environment’s initial capacity—the number of instances you want running at a minimum.

  • SpotFleetOnDemandBase doesn't affect initial capacity. When Spot is enabled, this option only determines how many On-Demand Instances are provisioned before any Spot Instances are considered.

  • Consider when SpotFleetOnDemandBase is less than MinSize. You'll still get exactly MinSize instances as initial capacity. At least SpotFleetOnDemandBase of them must be On-Demand Instances.

  • Consider when SpotFleetOnDemandBase is greater than MinSize. As your environment scales out, you're guaranteed to get at least an additional amount of instances equal to the difference between the two values. In other words, you're guaranteed to get at least an additional (SpotFleetOnDemandBase - MinSize) instances that are On-Demand before satisfying the SpotFleetOnDemandBase requirement.

In production environments, Spot Instances are particularly useful as part of a scalable, load-balanced environment. We don't recommend using Spot in a single-instance environment. If Spot Instances aren't available, you might lose the entire capacity (a single instance) of your environment. You may still wish to use a Spot Instance in a single instance environment for development or testing. When you do, be sure to set both SpotFleetOnDemandBase and SpotFleetOnDemandAboveBasePercentage to zero. Any other settings result in an On-Demand Instance.

Notes
  • Some older AWS accounts might provide Elastic Beanstalk with default instance types that don't support Spot Instances (for example, t1.micro). If you enable Spot Instance requests and you see the error None of the instance types you specified supports Spot, be sure to configure instance types that support Spot. To choose Spot Instance types, use the Spot Instance Advisor.

  • Enabling Spot Instance requests requires using Amazon EC2 launch templates. When you configure this feature during environment creation or updates, Elastic Beanstalk attempts to configure your environment to use Amazon EC2 launch templates (if the environment isn't using them already). In this case, if your user policy lacks the necessary permissions, environment creation or updates might fail. Therefore, we recommend that you use our managed user policy or add the required permissions to your custom policies. For details about the required permissions, see Creating a custom user policy.

The following examples demonstrate different scenarios of setting the various scaling options. All examples assume a load-balanced environment with Spot Instance requests enabled.

Example 1: On-Demand and Spot as part of initial capacity
Option settings
Option Namespace Value

MinSize

aws:autoscaling:asg

10

MaxSize

aws:autoscaling:asg

24

SpotFleetOnDemandBase

aws:ec2:instances

4

SpotFleetOnDemandAboveBasePercentage

aws:ec2:instances

50

In this example, the environment starts with ten instances, of which seven are On-Demand (four base, and 50% of the six above base) and three are Spot. The environment can scale out up to 24 instances. As it scales out, the portion of On-Demand in the part of the fleet above the four base On-Demand instances is kept at 50%, up to a maximum of 24 instances overall, of which 14 are On-Demand (four base, and 50% of the 20 above base) and ten are Spot.

Example 2: All On-Demand initial capacity
Option settings
Option Namespace Value

MinSize

aws:autoscaling:asg

4

MaxSize

aws:autoscaling:asg

24

SpotFleetOnDemandBase

aws:ec2:instances

4

SpotFleetOnDemandAboveBasePercentage

aws:ec2:instances

50

In this example, the environment starts with four instances, all of which are On-Demand. The environment can scale out up to 24 instances. As it scales out, the portion of On-Demand in the part of the fleet above the four base On-Demand instances is kept at 50%, up to a maximum of 24 instances overall, of which 14 are On-Demand (four base, and 50% of the 20 above base) and ten are Spot.

Example 3: Additional On-Demand base beyond initial capacity
Option settings
Option Namespace Value

MinSize

aws:autoscaling:asg

3

MaxSize

aws:autoscaling:asg

24

SpotFleetOnDemandBase

aws:ec2:instances

4

SpotFleetOnDemandAboveBasePercentage

aws:ec2:instances

50

In this example, the environment starts with three instances, all of which are On-Demand. The environment can scale out up to 24 instances. The first additional instance above the initial three is On-Demand, to complete the four base On-Demand instances. As it scales out further, the portion of On-Demand in the part of the fleet above the four base On-Demand instances is kept at 50%, up to a maximum of 24 instances overall, of which 14 are On-Demand (four base, and 50% of the 20 above base) and ten are Spot.