Setup overview for creating a mixed instances group
This topic provides an overview and best practices for creating an Auto Scaling mixed instances group.
Contents
Overview
To create a mixed instances group, you have two options:
-
Attribute-based instance type selection – Define your compute requirements to choose your instance types automatically based on their specific instance attributes.
-
Manual instance type selection – Manually choose the instance types that suit your workload.
Instance type flexibility
To enhance availability, deploy your application across multiple instance types. It's a best practice to use multiple instance types to satisfy capacity requirements. This way, Amazon EC2 Auto Scaling can launch another instance type if there is insufficient instance capacity in your chosen Availability Zones.
If there is insufficient instance capacity with Spot Instances, Amazon EC2 Auto Scaling keeps trying to launch from other Spot Instance pools. (The pools it uses are determined by your choice of instance types and allocation strategy.) Amazon EC2 Auto Scaling helps you leverage the cost savings of Spot Instances by launching them instead of On-Demand Instances.
We recommend being flexible across at least 10 instance types for each workload. When choosing your instance types, don't limit yourself to the most popular new instance types. Choosing earlier generation instance types tends to result in fewer Spot interruptions because they are less in demand from On-Demand customers.
Availability Zone flexibility
We strongly recommend that you span your Auto Scaling group across multiple Availability Zones. With multiple Availability Zones, you can design applications that automatically fail over between zones for greater resiliency.
As an added benefit, you can access a deeper Amazon EC2 capacity pool when compared to groups in a single Availability Zone. Because capacity fluctuates independently for each instance type in each Availability Zone, you can often get more compute capacity with flexibility for both the instance type and the Availability Zone.
For more information about using multiple Availability Zones, see Example: Distribute instances across Availability Zones.
Spot max price
When you create your Auto Scaling group using the AWS CLI or an SDK, you can specify the
SpotMaxPrice
parameter. The SpotMaxPrice
parameter
determines the maximum price that you're willing to pay for a Spot Instance hour.
When you specify the WeightedCapacity
parameter in your overrides (or
"DesiredCapacityType": "vcpu"
or "DesiredCapacityType":
"memory-mib"
at the group level), the maximum price represents the
maximum unit price, not the maximum price for a whole instance.
We strongly recommend that you do not specify a maximum price. Your application
might not run if you do not receive any Spot Instances, such as when your maximum
price is too low. If you don't specify a maximum price, the default maximum price is
the On-Demand price. You pay only the Spot price for the Spot Instances that you
launch. You still receive the steep discounts provided by Spot Instances. These
discounts are possible because of the stable Spot pricing that's available with the
Spot
pricing model
Proactive capacity rebalancing
If your use case allows, we recommend Capacity Rebalancing. Capacity Rebalancing helps you maintain workload availability by proactively augmenting your fleet with a new Spot Instance before a running Spot Instance receives the two-minute Spot Instance interruption notice.
When Capacity Rebalancing is enabled, Amazon EC2 Auto Scaling attempts to proactively replace Spot Instances that have received a rebalance recommendation. This provides an opportunity to rebalance your workload to new Spot Instances that are not at elevated risk of interruption.
For more information, see Use Capacity Rebalancing to handle Amazon EC2 Spot interruptions.
Scaling behavior
When you create a mixed instances group, it uses On-Demand Instances by default. To use Spot Instances, you must modify the percentage of the group to be launched as On-Demand Instances. You can specify any number from 0 to 100 for the On-Demand percentage.
Optionally, you can also designate a base number of On-Demand Instances to start with. If you do so, Amazon EC2 Auto Scaling waits to launch Spot Instances until after it launches the base capacity of On-Demand Instances when the group scales out. Anything beyond the base capacity uses the On-Demand percentage to determine how many On-Demand Instances and Spot Instances to launch.
Amazon EC2 Auto Scaling converts the percentage to the equivalent number of instances. If the result creates a fractional number, it rounds up to the next integer in favor of On-Demand Instances.
The following table demonstrates the behavior of the Auto Scaling group as it increases and decreases in size.
Purchase options | Group size and number of running instances across purchase options | |||
---|---|---|---|---|
10 | 20 | 30 | 40 | |
Example 1: base of 10, 50/50% On-Demand/Spot |
||||
On-Demand Instances (base amount) | 10 | 10 | 10 | 10 |
On-Demand Instances | 0 | 5 | 10 | 15 |
Spot Instances | 0 | 5 | 10 | 15 |
Example 2: base of 0, 0/100% On-Demand/Spot |
||||
On-Demand Instances (base amount) | 0 | 0 | 0 | 0 |
On-Demand Instances | 0 | 0 | 0 | 0 |
Spot Instances | 10 | 20 | 30 | 40 |
Example 3: base of 0, 60/40% On-Demand/Spot |
||||
On-Demand Instances (base amount) | 0 | 0 | 0 | 0 |
On-Demand Instances | 6 | 12 | 18 | 24 |
Spot Instances | 4 | 8 | 12 | 16 |
Example 4: base of 0, 100/0% On-Demand/Spot |
||||
On-Demand Instances (base amount) | 0 | 0 | 0 | 0 |
On-Demand Instances | 10 | 20 | 30 | 40 |
Spot Instances | 0 | 0 | 0 | 0 |
Example 5: base of 12, 0/100% On-Demand/Spot |
||||
On-Demand Instances (base amount) | 10 | 12 | 12 | 12 |
On-Demand Instances | 0 | 0 | 0 | 0 |
Spot Instances | 0 | 8 | 18 | 28 |
When the size of the group increases, Amazon EC2 Auto Scaling attempts to balance your capacity evenly across your specified Availability Zones. Then, it launches instance types according to the specified allocation strategy.
When the size of the group decreases, Amazon EC2 Auto Scaling first identifies which of the two types (Spot or On-Demand) should be terminated. Then, it tries to terminate instances in a balanced way across your specified Availability Zones. It also favors terminating instances in a way that aligns closer to your allocation strategies. For information about termination policies, see Configure termination policies for Amazon EC2 Auto Scaling.
Regional availability of instance types
The availability of EC2 instance types varies depending on your AWS Region. For example, the newest generation instance types might not yet be available in a given Region. Due to the variances in instance availability across Regions, you might encounter issues when making programmatic requests if multiple instance types in your overrides are not available in your Region. Using multiple instance types that are not available in your Region might cause the request to fail entirely. To solve the issue, retry the request with different instance types, making sure that each instance type is available in the Region. To search for instance types offered by location, use the describe-instance-type-offerings command. For more information, see Finding an Amazon EC2 instance type in the Amazon EC2 User Guide.
Related resources
For more best practices for Spot Instances, see Best practices for EC2 Spot in the Amazon EC2 User Guide.
Limitations
After you add overrides to an Auto Scaling group using a mixed instances
policy, you can update the overrides with the
UpdateAutoScalingGroup
API call but not delete them. To completely
remove the overrides, you must first switch the Auto Scaling group to use a launch template
or launch configuration instead of a mixed instances policy. Then, you can add a
mixed instances policy again without any overrides.