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: filters instances to find the ones that were created based on the earliest scaling configuration and launch template. Manually added instances are not associated with scaling configurations or launch templates. Therefore, manually added instances are not filtered first. If all instances associated with all scaling configurations and launch templates have been removed but Auto Scaling must remove more instances from the scaling group, manually added instances are removed at random.
      Note Scaling Configuration in Earliest Instance Created Using Scaling Configuration indicates the instance configuration source, which includes scaling configurations and launch templates.

      The version of a launch template does not indicate the order in which the template was added. For example, you select the lt-foress V2 template when you create a scaling group. Then, you select the lt-foress V1 template to modify the scaling group. The scaling group considers the lt-foress V2 launch template as the template that was added earlier.

    • Earliest Created Instance: filters instances to find the instances that were created at the earliest point in time.
    • Most Recent Created Instance: filters instances to find the most recently created instances.
    • No Policy: This value is available only for Then Remove from Results. This value indicates that Auto Scaling does not filter instances based on the Then Remove from Results field.
Note
  • For information about how to specify a combination policy, see Create a scaling group.
  • 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 ID Zone Added at Scaling configuration

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

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

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 step Valid value for the second step Description ID of the removed instance
Earliest Instance Created Using Scaling Configuration Earliest Created Instance Filters 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 Instance Filters 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 Policy Filters 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 Instance Most Recent Created Instance Removes the instances that were created at the earliest points in time. i-1
Earliest Instance Created Using Scaling Configuration Filters 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 Policy Removes the instances that were created at the earliest points in time. i-1
Most Recent Created Instance Earliest Created Instance Removes the most recently created instances. i-5
Earliest Instance Created Using Scaling Configuration Filters 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 Policy Removes 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 step Valid value for the second step Description ID of the removed instance
Earliest Instance Created Using Scaling Configuration Earliest Created Instance Filters 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 Instance Filters 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 Policy Filters 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 Instance Most Recent Created Instance Removes the instances that were created at the earliest points in time. i-2
Earliest Instance Created Using Scaling Configuration Filters 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 Policy Removes the instances that were created at the earliest points in time. i-2
Most Recent Created Instance Earliest Created Instance Removes the most recently created instances. i-5
Earliest Instance Created Using Scaling Configuration Filters 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 Policy Removes 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 step Valid value for the second step Description ID of the removed instance
Earliest Instance Created Using Scaling Configuration Earliest Created Instance Filters 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 Instance Filters 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 Policy Filters 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 Instance Most Recent Created Instance Removes the instances that were created at the earliest points in time. i-3
Earliest Instance Created Using Scaling Configuration Filters 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 Policy Removes the instances that were created at the earliest points in time. i-3
Most Recent Created Instance Earliest Created Instance Removes the most recently created instances. i-5
Earliest Instance Created Using Scaling Configuration Filters 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 Policy Removes the most recently created instances. i-5