Create a mixed instances group using attribute-based instance type selection
Instead of manually choosing instance types for your mixed instances group, you can specify a set of instance attributes that describe your compute requirements. As Amazon EC2 Auto Scaling launches instances, any instance types used by the Auto Scaling group must match your required instance attributes. This is known as attribute-based instance type selection.
Your Auto Scaling group specifies your instance attributes. These attributes include the amount of memory and computing power that you need for the applications that you plan to run on the instances. Also, your Auto Scaling group specifies two price protection thresholds for Spot and On-Demand Instances that you can customize. This way, you can prevent Amazon EC2 Auto Scaling from launching more expensive instance types if you don’t need them.
This approach is ideal for workloads and frameworks that can be flexible about which instance types they use, such as containers, big data, and CI/CD.
The following are benefits of attribute-based instance type selection:
-
Amazon EC2 Auto Scaling can select from a wide range of instance types for launching Spot Instances. This meets the Spot best practice of being flexible about instance types, which gives the Amazon EC2 Spot service a better chance of finding and allocating your required amount of compute capacity.
-
With so many options available, finding the right instance types for your workload can be time consuming. By specifying instance attributes, you can simplify instance type selection when configuring a mixed instances group.
-
Your Auto Scaling groups can use newer generation instance types as they're released. Newer generation instance types are automatically used when they match your requirements and align with the allocation strategies you choose for your Auto Scaling group.
Contents
Preview your instance types
You can preview the instance types that match your compute requirements without launching them and adjust your requirements if necessary. When creating your Auto Scaling group in the Amazon EC2 Auto Scaling console, a preview of the instance types appears in the Preview matching instance types section on the Choose instance launch options page.
Alternatively, you can preview the instance types by making an Amazon EC2 GetInstanceTypesFromInstanceRequirements API call using the Amazon CLI or an
SDK. Pass the InstanceRequirements
parameters in the request in the exact
format that you would use to create or update an Auto Scaling group. For more information, see
Preview instance types with specified attributes in the
Amazon EC2 User Guide for Linux Instances.
Understand price protection
Price protection protects your Auto Scaling group from extreme price differences across instance types. When you create a new Auto Scaling group or update an existing Auto Scaling group with attribute-based instance type selection, we enable price protection by default.
Optionally, you can choose your price protection thresholds for Spot and On-Demand Instances. When you do this, Amazon EC2 Auto Scaling doesn't select instance types with prices higher than your specified thresholds. The thresholds represent what you are willing to pay, defined in terms of a percentage above baseline instead of absolute values.
The baseline is determined by the price of the least expensive current generation M, C, or R instance type with your specified attributes. If your attributes don't match any M, C, or R instance types, we use the lowest priced instance type.
If you don't specify a threshold, the following default price protection thresholds apply:
-
On-Demand Instances – 20 percent
-
Spot Instances – 100 percent
You can update these values when creating your Auto Scaling group in the Amazon EC2 Auto Scaling console. On the Choose instance launch options page, choose the desired price protection attribute from the Additional instance attributes dropdown list. Then, type or choose a value for the attribute in the text box.
You can also update these values later by editing the Auto Scaling group from the console or by using the Amazon CLI or an SDK.
If you set Desired capacity type to vCPUs or Memory GiB, the price protection threshold is applied based on the per vCPU or per memory price instead of the per instance price.
Prerequisites
-
Create a launch template. For more information, see Create a launch template for an Auto Scaling group.
-
Verify that the launch template doesn't already request Spot Instances.
Create a mixed instances group (console)
Use the following procedure to create a mixed instances group by using attribute-based instance type selection. To help you move through the steps efficiently, some optional sections are skipped.
For most general purpose workloads, it's enough to specify the number of vCPUs and memory that you need. For advanced use cases, you can specify attributes like storage type, network interfaces, CPU manufacturer, and accelerator type.
To review the steps for setting up a mixed instances group, see Setup overview.
To create a mixed instances group
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
, and choose Auto Scaling Groups from the navigation pane. -
On the navigation bar at the top of the screen, choose the same Amazon Web Services Region that you used when you created the launch template.
-
Choose Create an Auto Scaling group.
-
On the Choose launch template or configuration page, for Auto Scaling group name, enter a name for your Auto Scaling group.
-
To choose your launch template, do the following:
-
For Launch template, choose an existing launch template.
-
For Launch template version, choose whether the Auto Scaling group uses the default, the latest, or a specific version of the launch template when scaling out.
-
Verify that your launch template supports all of the options that you are planning to use, and then choose Next.
-
-
On the Choose instance launch options page, do the following:
-
Under Network, for VPC, choose a VPC. The Auto Scaling group must be created in the same VPC as the security group you specified in your launch template.
-
For Availability Zones and subnets, choose one or more subnets in the specified VPC. Use subnets in multiple Availability Zones for high availability. For more information, see Considerations when choosing VPC subnets.
-
For Instance type requirements, choose Override launch template.
Note
If you chose a launch template that already contains a set of instance attributes, such as vCPUs and memory, then the instance attributes are displayed. These attributes are added to the Auto Scaling group properties, where you can update them from the Amazon EC2 Auto Scaling console at any time.
-
Under Specify instance attributes, start by entering your vCPUs and memory requirements.
-
vCPUs: Enter the minimum and maximum number of vCPUs for your compute requirements. Alternatively, select the No minimum or No maximum check box.
-
Memory (GiB): Enter the minimum and maximum amount of memory, in GiB, for your compute requirements. Alternatively, select the No minimum or No maximum check box.
-
-
(Optional) For Additional instance attributes, choose Add attribute to express your compute requirements in more detail. The attributes and values that you choose here further define which instance types can be launched. For supported attributes, see InstanceRequirements in the Amazon EC2 Auto Scaling API Reference.
-
For Preview matching instance types, view the instance types that match the specified compute requirements, such as vCPUs, memory, and storage.
-
Under Instance purchase options, for Instances distribution, specify the percentages of the group to launch as On-Demand Instances and as Spot Instances. If your application is stateless, fault tolerant, and can handle an instance being interrupted, you can specify a higher percentage of Spot Instances.
-
(Optional) When you specify a percentage for Spot Instances, select Include On-Demand base capacity and then specify the minimum amount of the Auto Scaling group's initial capacity that must be fulfilled by On-Demand Instances. Anything beyond the base capacity uses the Instances distribution settings to determine how many On-Demand Instances and Spot Instances to launch.
-
Under Allocation strategies, Lowest price is automatically selected for the On-Demand allocation strategy and cannot be changed.
-
For Spot allocation strategy, choose an allocation strategy. Price capacity optimized is selected by default. Lowest price is hidden by default and only appears when you choose Show all strategies. If you choose Lowest price, enter the number of lowest priced pools to diversify across for Lowest priced pools.
-
For Capacity rebalance, choose whether to enable or disable Capacity Rebalancing. Use Capacity Rebalancing to automatically respond when your Spot Instances approach termination from a Spot interruption. For more information, see Use Capacity Rebalancing to handle Amazon EC2 Spot interruptions.
-
Choose Next, Next.
-
-
For the Configure group size and scaling policies step, do the following:
-
To measure your desired capacity in units other than instances, choose the appropriate option for Desired capacity type. Units, vCPUs, and Memory GiB are supported. By default, Amazon EC2 Auto Scaling specifies Units, which translates into number of instances.
-
Enter the initial size of your Auto Scaling group for Desired capacity and update the Minimum capacity and Maximum capacity limits as needed. For more information, see Set capacity limits on your Auto Scaling group.
-
-
Choose Skip to review.
-
On the Review page, choose Create Auto Scaling group.
Create a mixed instances group (Amazon CLI)
To create a mixed instances group using the command line
Use one of the following commands:
-
create-auto-scaling-group (Amazon CLI)
-
New-ASAutoScalingGroup (Amazon Tools for Windows PowerShell)
Example configuration
To create an Auto Scaling group with attribute-based instance type selection by using the Amazon CLI, use the following create-auto-scaling-group command.
The following instance attributes are specified:
-
VCpuCount
– The instance types must have a minimum of four vCPUs and a maximum of eight vCPUs. -
MemoryMiB
– The instance types must have a minimum of 16,384 MiB of memory. -
CpuManufacturers
– The instance types must have an Intel manufactured CPU.
aws autoscaling create-auto-scaling-group --cli-input-json
file://~/config.json
The following is an example config.json
file.
{ "AutoScalingGroupName": "
my-asg
", "DesiredCapacityType": "units", "MixedInstancesPolicy": { "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "my-launch-template
", "Version": "$Default
" }, "Overrides": [{ "InstanceRequirements": { "VCpuCount": {"Min":4
, "Max":8
}, "MemoryMiB": {"Min":16384
}, "CpuManufacturers": ["intel"] } }] }, "InstancesDistribution": { "OnDemandPercentageAboveBaseCapacity":50
, "SpotAllocationStrategy": "price-capacity-optimized" } }, "MinSize":, "MaxSize":
0
, "DesiredCapacity":
100
, "DesiredCapacityType": "units", "VPCZoneIdentifier": "
4
subnet-5ea0c127
,subnet-6194ea3b
,subnet-c934b782
" }
To set the value for desired capacity as the number of vCPUs or the amount of
memory, specify "DesiredCapacityType": "vcpu"
or
"DesiredCapacityType": "memory-mib"
in the file. The default
desired capacity type is units
, which sets the value for desired
capacity as the number of instances.
Alternatively, you can use the following create-auto-scaling-group
aws autoscaling create-auto-scaling-group --cli-input-yaml
file://~/config.yaml
The following is an example config.yaml
file.
--- AutoScalingGroupName:
my-asg
DesiredCapacityType: units MixedInstancesPolicy: LaunchTemplate: LaunchTemplateSpecification: LaunchTemplateName:my-launch-template
Version:$Default
Overrides: - InstanceRequirements: VCpuCount: Min: 2 Max: 4 MemoryMiB: Min: 2048 CpuManufacturers: - intel InstancesDistribution: OnDemandPercentageAboveBaseCapacity:50
SpotAllocationStrategy: price-capacity-optimized MinSize:0
MaxSize:100
DesiredCapacity:4
DesiredCapacityType: units VPCZoneIdentifier:subnet-5ea0c127
,subnet-6194ea3b
,subnet-c934b782
To set the value for desired capacity as the number of vCPUs or the amount of
memory, specify DesiredCapacityType: vcpu
or
DesiredCapacityType: memory-mib
in the file. The default
desired capacity type is units
, which sets the value for desired
capacity as the number of instances.
Related resources
To learn more about attribute-based instance type selection, see Attribute-Based Instance Type Selection for EC2 Auto Scaling and EC2 Fleet
You can declare attribute-based instance type selection when you create an Auto Scaling group using Amazon CloudFormation. For more information, see the example snippet in the Auto scaling template snippets section of the Amazon CloudFormation User Guide.