Configure an Auto Scaling group to use instance weights - Amazon EC2 Auto Scaling
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Configure an Auto Scaling group to use instance weights

When you use multiple instance types, you can specify how many units to associate with each instance type, and then specify the capacity of your group with the same unit of measurement. This capacity specification option is known as weights.

For example, let's say that you run a compute-intensive application that performs best with at least 8 vCPUs and 15 GiB of RAM. If you use c5.2xlarge as your base unit, any of the following EC2 instance types would meet your application needs.

Instance types example
Instance type vCPU Memory (GiB)
c5.2xlarge 8 16
c5.4xlarge 16 32
c5.12xlarge 48 96
c5.18xlarge 72 144
c5.24xlarge 96 192

By default, all instance types have equal weight regardless of size. In other words, whether Amazon EC2 Auto Scaling launches a large or small instance type, each instance counts the same toward the desired capacity of the Auto Scaling group.

With weights, however, you assign a number value that specifies how many units to associate with each instance type. For example, if the instances are of different sizes, a c5.2xlarge instance could have the weight of 2, and a c5.4xlarge (which is two times bigger) could have the weight of 4, and so on. Then, when Amazon EC2 Auto Scaling scales the group, these weights translate into the number of units that each instance counts toward your desired capacity.

The weights do not change which instance types Amazon EC2 Auto Scaling chooses to launch; instead, the allocation strategies do that. For more information, see Allocation strategies.

Important

To configure an Auto Scaling group to fulfill its desired capacity using the number of vCPUs or the amount of memory of each instance type, we recommend using attribute-based instance type selection. Setting the DesiredCapacityType parameter automatically specifies the number of units to associate with each instance type based on the value that you set for this parameter. For more information, see Create a mixed instances group using attribute-based instance type selection.

Considerations

This section discusses key considerations for effectively implementing weights.

  • Choose a few instance types that match your application's performance needs. Decide the weight each instance type should count toward the desired capacity of your Auto Scaling group based on its capabilities. These weights apply to current and future instances.

  • Avoid large ranges between weights. For example, don't specify a weight of 1 for an instance type when the next larger instance type has a weight of 200. The difference between the smallest and largest weights shouldn't be extreme, either. Extreme weight differences can negatively impact cost-performance optimization.

  • Specify the group's desired capacity in units, not instances. For example, if you use vCPU-based weights, set your desired number of cores and also the minimum and maximum.

  • Set your weights and desired capacity so that the desired capacity is at least two to three times larger than your largest weight.

Note the following when updating existing groups:

  • When you add weights to an existing group, include weights for all instance types currently in use.

  • When you add or change weights, Amazon EC2 Auto Scaling will launch or terminate instances to reach the desired capacity based on the new weight values.

  • If you remove an instance type, running instances of that type keep their last weight, even if no longer defined.

Instance weight behaviors

When you use instance weights, Amazon EC2 Auto Scaling behaves in the following way:

  • Current capacity will either be at the desired capacity or above it. Current capacity can exceed the desired capacity if instances launched that exceed the remaining desired capacity units. For example, suppose that you specify two instance types, c5.2xlarge and c5.12xlarge, and you assign instance weights of 2 for c5.2xlarge and 12 for c5.12xlarge. If there are five units remaining to fulfill the desired capacity, and Amazon EC2 Auto Scaling provisions a c5.12xlarge, the desired capacity is exceeded by seven units.

  • When launching instances, Amazon EC2 Auto Scaling prioritizes distributing capacity across Availability Zones and respecting allocation strategies over exceeding the desired capacity.

  • Amazon EC2 Auto Scaling can exceed the maximum capacity limit to maintain balance across Availability Zones, using your preferred allocation strategies. The hard limit enforced by Amazon EC2 Auto Scaling is your desired capacity plus your largest weight.

Configure an Auto Scaling group to use weights

You can configure an Auto Scaling group to use weights, as shown in the following Amazon CLI examples. For instructions on using the console, see Create a mixed instances group by manually choosing instance types.

To configure a new Auto Scaling group to use weights (Amazon CLI)

Use the create-auto-scaling-group command. For example, the following command creates a new Auto Scaling group and assigns weights by specifying the following:

  • The percentage of the group to launch as On-Demand Instances (0)

  • The allocation strategy for Spot Instances in each Availability Zone (capacity-optimized)

  • The instance types to launch in priority order (m4.16xlarge, m5.24xlarge)

  • The instance weights that correspond to the relative size difference (vCPUs) between instance types (16, 24)

  • The subnets in which to launch the instances (subnet-5ea0c127, subnet-6194ea3b, subnet-c934b782), each corresponding to a different Availability Zone

  • The launch template (my-launch-template) and the launch template version ($Latest)

aws autoscaling create-auto-scaling-group --cli-input-json file://~/config.json

The config.json file contains the following content.

{ "AutoScalingGroupName": "my-asg", "MixedInstancesPolicy": { "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "my-launch-template", "Version": "$Latest" }, "Overrides": [ { "InstanceType": "m4.16xlarge", "WeightedCapacity": "16" }, { "InstanceType": "m5.24xlarge", "WeightedCapacity": "24" } ] }, "InstancesDistribution": { "OnDemandPercentageAboveBaseCapacity": 0, "SpotAllocationStrategy": "capacity-optimized" } }, "MinSize": 160, "MaxSize": 720, "DesiredCapacity": 480, "VPCZoneIdentifier": "subnet-5ea0c127,subnet-6194ea3b,subnet-c934b782", "Tags": [] }
To configure an existing Auto Scaling group to use weights (Amazon CLI)

Use the update-auto-scaling-group command. For example, the following command assigns weights to instance types in an existing Auto Scaling group by specifying the following:

  • The instance types to launch in priority order (c5.18xlarge, c5.24xlarge, c5.2xlarge, c5.4xlarge)

  • The instance weights that correspond to the relative size difference (vCPUs) between instance types (18, 24, 2, 4)

  • The new, increased desired capacity, which is larger than the largest weight

aws autoscaling update-auto-scaling-group --cli-input-json file://~/config.json

The config.json file contains the following content.

{ "AutoScalingGroupName": "my-existing-asg", "MixedInstancesPolicy": { "LaunchTemplate": { "Overrides": [ { "InstanceType": "c5.18xlarge", "WeightedCapacity": "18" }, { "InstanceType": "c5.24xlarge", "WeightedCapacity": "24" }, { "InstanceType": "c5.2xlarge", "WeightedCapacity": "2" }, { "InstanceType": "c5.4xlarge", "WeightedCapacity": "4" } ] } }, "MinSize": 0, "MaxSize": 100, "DesiredCapacity": 100 }
To verify the weights using the command line

Use one of the following commands:

Spot price per unit hour example

The following table compares the hourly price for Spot Instances in different Availability Zones in US East (Northern Virginia) with the price for On-Demand Instances in the same Region. The prices shown are example pricing and not current pricing. These are your costs per instance hour.

Example: Spot pricing per instance hour
Instance type us-east-1a us-east-1b us-east-1c On-Demand pricing
c5.2xlarge $0.180 $0.191 $0.170 $0.34
c5.4xlarge $0.341 $0.361 $0.318 $0.68
c5.12xlarge $0.779 $0.777 $0.777 $2.04
c5.18xlarge $1.207 $1.475 $1.357 $3.06
c5.24xlarge $1.555 $1.555 $1.555 $4.08

With instance weights, you can evaluate your costs based on what you use per unit hour. You can determine the price per unit hour by dividing your price for an instance type by the number of units that it represents. For On-Demand Instances, the price per unit hour is the same when deploying one instance type as it is when deploying a different size of the same instance type. In contrast, however, the Spot price per unit hour varies by Spot pool.

The following example shows how the Spot price per unit hour calculation works with instance weights. For ease of calculation, let's say you want to launch Spot Instances only in us-east-1a. The per unit hour price is captured in the following table.

Example: Spot Price per unit hour example
Instance type us-east-1a Instance weight Price per unit hour
c5.2xlarge $0.180 2 $0.090
c5.4xlarge $0.341 4 $0.085
c5.12xlarge $0.779 12 $0.065
c5.18xlarge $1.207 18 $0.067
c5.24xlarge $1.555 24 $0.065