When you create a scaling group, you must specify an appropriate combination policy for removing Elastic Compute Service (ECS) instances. This topic describes how combination policies take effect and provides policy examples to help you choose a combination policy that matches your business scenarios.

Background information

A combination policy for removing instances consists of the following policies. ECS instances are removed from a scaling group based on a combination policy.
  • Scaling policy: adds ECS instances to or removes ECS instances from a scaling group based on zones or instance costs. When a scale-in event is triggered, Auto Scaling filters and removes ECS instances based on the scaling policy. Valid values for the Scaling Policy parameter:
    • Priority Policy: The first specified vSwitch has the highest priority. Auto Scaling preferentially attempts to scale ECS instances in the zone where the vSwitch with the highest priority resides. If the scaling fails, Auto Scaling attempts to scale instances in the zone where the vSwitch with the next highest priority resides.
    • Balanced Distribution Policy: This policy is valid when a scaling group is associated with multiple vSwitches that are distributed across more than two zones. After a scale-in or scale-out event is complete, Auto Scaling evenly distributes ECS instances across the zones where the vSwitches reside.
    • Cost Optimization Policy: This policy is valid when you specify multiple instance types in the active scaling configuration. When a scale-out event is triggered, Auto Scaling attempts to create ECS instances based on the unit prices of vCPUs in ascending order. When a scale-in event is triggered, Auto Scaling attempts to remove ECS instances based on the unit prices of vCPUs in descending order.
  • Instance removing policy: filters ECS instances that meet the specified conditions in a scaling group based on the order of time. Valid values for the two steps of an instance removing policy:
    Note An instance removing policy consists of two steps:
    • If you configure only one step for the policy, Auto Scaling filters instances to find the ones that meet the requirements of the one step.
    • If you configure two steps for the policy, Auto Scaling filters instances to find the ones that meet the requirements of the first step and then filters instances in the filtering result to find the ones that meet the requirements of the second step. You cannot configure the same value for the two steps.
    • Earliest Instance Created Using Scaling Configuration: Auto Scaling removes instances that are created based on the earliest scaling configuration or the earliest launch template. No scaling configuration or launch template is associated with instances that are manually added to the scaling group. Therefore, manually added instances are not removed first. If more instances need to be removed from a scaling group after Auto Scaling removes all instances with which the earliest scaling configuration or the earliest launch template is associated, Auto Scaling removes manually added instances in a random manner.
      Note The scaling configuration source in the Earliest Instance Created Using Scaling Configuration setting can be a scaling configuration or a launch template.

      The version of a launch template does not indicate the order in which the template is added. For example, if you specify the lt-foress V2 launch template when you create a scaling group, and then replace the template with the lt-foress V1 launch template when you modify the scaling group, Auto Scaling considers the lt-foress V2 launch template as the earliest template.

    • Earliest Created Instance: Auto Scaling removes the instances that are created at the earliest point in time.
    • Most Recent Created Instance: Auto Scaling removes the instances that are created at the latest point in time.
    • No Policy: This setting is available only for the Then Remove field. If you select No Policy, Auto Scaling does not remove instances from the results that are obtained based on the First Remove field.
Note
  • For information about how to specify a combination policy, see Manage scaling groups.
  • If multiple ECS instances in a scaling group meet the requirements of a combination policy, Auto Scaling randomly removes one of these ECS instances from the scaling group.
  • For information about how to avoid removing manually added ECS instances, see Put an ECS instance into the Protected state.

The following table describes the ECS instances in a scaling group. In the following examples, different types of scaling policies are used to demonstrate how Auto Scaling removes an ECS instance based on different combination policies.

Note Data of each instance in the following table are for reference only. The actual data in the Auto Scaling console prevails.
Instance IDZoneAdded at Scaling configuration

(asc-1 was added at the earliest point in time)

Unit price of vCPUs (USD)
i-1Hangzhou Zone H11:05, May 17, 2021asc-11
i-2Hangzhou Zone I11:05, May 18, 2021asc-12
i-3Hangzhou Zone I11:05, May 19, 2021asc-13
i-4Hangzhou Zone H11:05, May 20, 2021asc-23
i-5Hangzhou Zone I11:05, May 21, 2021asc-23

Scenario 1: The priority policy is used as the scaling policy by default

Auto Scaling filters ECS instances to find the ones that meet the requirements of the instance removing policy. The priority policy does not affect the filtering result. The following table describes the final effect of the combination policy.

Valid value for the first stepValid value for the second stepDescriptionID of the removed instance
Earliest Instance Created Using Scaling ConfigurationEarliest Created InstanceFilters instances to find the ones that were created based on the earliest scaling configuration and then removes the instances that were created at the earliest points in time from the filtering result.i-1
Most Recent Created InstanceFilters instances to find the ones that were created based on the earliest scaling configuration and then removes the most recently created instances from the filtering result.i-3
No PolicyFilters instances to find the ones that were created based on the earliest scaling configuration and then randomly removes an instance from the filtering result.
  • i-1
  • i-2
  • i-3
Earliest Created InstanceMost Recent Created InstanceRemoves the instances that were created at the earliest points in time.i-1
Earliest Instance Created Using Scaling ConfigurationFilters instances to find the ones that were created at the earliest points in time and then removes the instances that were created based on the earliest scaling configuration from the filtering result.i-1
No PolicyRemoves the instances that were created at the earliest points in time.i-1
Most Recent Created InstanceEarliest Created InstanceRemoves the most recently created instances.i-5
Earliest Instance Created Using Scaling ConfigurationFilters instances to find the most recently created ones and then removes the instances that were created based on the earliest scaling configuration from the filtering result.i-5
No PolicyRemoves the most recently created instances.i-5

Scenario 2: The scaling policy is a balanced distribution policy

Auto Scaling finds the zones where the ECS instances reside based on the balanced distribution policy and then filters and removes the instances that meet the requirements of the instance removing policy. This ensures that the existing instances in the scaling group are evenly distributed across the zones after instances are removed from the scaling group.

In this example, Auto Scaling filters instances to find the i-2, i-3, and i-5 instances in Hangzhou Zone I based on the balanced distribution policy. This is because Hangzhou Zone I has one more instance than Hangzhou Zone H. The following table describes the final effect of the combination policy.

Valid value for the first stepValid value for the second stepDescriptionID of the removed instance
Earliest Instance Created Using Scaling ConfigurationEarliest Created InstanceFilters instances to find the ones that were created based on the earliest scaling configuration and then removes the instances that were created at the earliest points in time from the filtering result.i-2
Most Recent Created InstanceFilters instances to find the ones that were created based on the earliest scaling configuration and then removes the most recently created instances from the filtering result.i-3
No PolicyFilters instances to find the ones that were created based on the earliest scaling configuration and then randomly removes an instance from the filtering result.
  • i-2
  • i-3
Earliest Created InstanceMost Recent Created InstanceRemoves the instances that were created at the earliest points in time.i-2
Earliest Instance Created Using Scaling ConfigurationFilters instances to find the ones that were created at the earliest points in time and then removes the instances that were created based on the earliest scaling configuration from the filtering result.i-2
No PolicyRemoves the instances that were created at the earliest points in time.i-2
Most Recent Created InstanceEarliest Created InstanceRemoves the most recently created instances.i-5
Earliest Instance Created Using Scaling ConfigurationFilters instances to find the most recently created ones and then removes the instances that were created based on the earliest scaling configuration from the filtering result.i-5
No PolicyRemoves the most recently created instances.i-5

Scenario 3: The scaling policy is a cost optimization policy

Auto Scaling filters and removes the ECS instances that have the highest vCPU unit price based on the cost optimization policy. If multiple instances that have the highest vCPU unit price exist in the scaling group, Auto Scaling filters and removes instances based on the instance removal policy.

In this example, Auto Scaling filter instances to find the i-3, i-4, i-5 instances based on the cost optimization policy. This is because these instances have the same highest unit price of vCPU, which is USD 3. The following table describes the final effect of the combination policy.

Valid value for the first stepValid value for the second stepDescriptionID of the removed instance
Earliest Instance Created Using Scaling ConfigurationEarliest Created InstanceFilters instances to find the ones that were created based on the earliest scaling configuration and then removes the instances that were created at the earliest points in time from the filtering result.i-3
Most Recent Created InstanceFilters instances to find the ones that were created based on the earliest scaling configuration and then removes the most recently created instances from the filtering result.i-3
No PolicyFilters instances to find the ones that were created based on the earliest scaling configuration and then randomly removes an instance from the filtering result.i-3
Earliest Created InstanceMost Recent Created InstanceRemoves the instances that were created at the earliest points in time.i-3
Earliest Instance Created Using Scaling ConfigurationFilters instances to find the ones that were created at the earliest points in time and then removes the instances that were created based on the earliest scaling configuration from the filtering result.i-3
No PolicyRemoves the instances that were created at the earliest points in time.i-3
Most Recent Created InstanceEarliest Created InstanceRemoves the most recently created instances.i-5
Earliest Instance Created Using Scaling ConfigurationFilters instances to find the most recently created ones and then removes the instances that were created based on the earliest scaling configuration from the filtering result.i-5
No PolicyRemoves the most recently created instances.i-5