All Products
Search
Document Center

Auto Scaling:Configure an instance termination policy for a scaling group

Last Updated:Sep 07, 2026

An instance termination policy controls which ECS instances are removed first during a scale-in activity. You can configure a scaling policy and a scale-in policy when you create or modify a scaling group. Auto Scaling combines both policies to automate instance selection. This topic explains how each policy component works and provides examples to help you choose the right termination policy for your scenario.

Instance termination policy

An ECS instance termination policy is a combination of a Scaling Policy and a Instance Removing Policy. When a scaling group removes an ECS instance, the removal is constrained by both policies.

Scaling policy

A scaling policy adds or removes ECS instances based on the zone or the cost of the instances. During a scale-in event, Auto Scaling filters and removes instances from the scaling group based on the policy rules. The following policies are available:

  • Priority Policy: The vSwitch that you specify first has the highest priority. Auto Scaling preferentially attempts scale-out and scale-in activities in the zone where the vSwitch with the highest priority resides. If the activities cannot be performed, Auto Scaling automatically performs them in the zone where the vSwitch with the next highest priority resides.

  • Balanced Distribution Policy: This policy takes effect when the scaling group is associated with multiple vSwitches and the vSwitches are distributed across more than two zones. After a scale-out or scale-in activity, the ECS instances are evenly distributed across the zones where the vSwitches of the scaling group reside.

  • Cost Optimization Policy: This policy takes effect when multiple optional instance types are specified in the scaling configuration. During a scale-out event, Auto Scaling attempts to create ECS instances in ascending order of the unit price of vCPUs. During a scale-in event, Auto Scaling attempts to remove ECS instances in descending order of the unit price of vCPUs.

    Note

    When multiple instance types that use the preemptible billing method are specified in the scaling configuration, Auto Scaling preferentially creates the corresponding preemptible instances. If none of the preemptible instance types can be created due to reasons such as insufficient inventory, the system automatically attempts to create ECS instances that use the pay-as-you-go billing method.

  • Custom Combination Policy: Uses a combination to customize the capacity distribution policy. You can use this policy to adjust the ratio of pay-as-you-go instances to preemptible instances in the scaling group, balance the capacity across zones, and select the instance types that meet your requirements.

Scale-in policy

A scale-in policy filters the eligible ECS instances in the scaling group based on the chronological order. A scale-in policy supports two stages:

  • If you configure only one stage, Auto Scaling filters instances based only on the first stage.

  • If you configure two stages, Auto Scaling first filters instances based on the first stage, and then performs the second filtering on the filtering result. You cannot set the same option for the two stages.

The following policies are available:

  • Instances Created From Earliest 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, instances that are manually added 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 randomly.

    Note

    The scaling configuration source in the Instances Created From Earliest 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 Instances: Auto Scaling removes the instances that are created at the earliest point in time.

  • Most Recent Instances: Auto Scaling removes the instances that are created at the most recent point in time.

  • Custom Policy: Auto Scaling removes instances from the scaling group based on a custom policy. The custom policy contains a service, version, and function.

ECS instance removal examples

The following examples use the ECS instances listed in the following table. Each scenario shows how Auto Scaling removes one ECS instance under a different instance termination policy combination (Scaling Policy + Instance Removing Policy).

Note

The data of each ECS instance in the following table is for example purposes only. For the actual data, see the Auto Scaling console.

Instance ID

Zone

Time added

Scaling configuration(asc-1 was added the earliest)

Unit price of vCPUs(USD)

i-1

Hangzhou Zone H

May 17, 2021, 11:05

asc-1

1

i-2

Hangzhou Zone I

May 18, 2021, 11:05

asc-1

2

i-3

Hangzhou Zone I

May 19, 2021, 11:05

asc-1

3

i-4

Hangzhou Zone H

May 20, 2021, 11:05

asc-2

3

i-5

Hangzhou Zone I

May 21, 2021, 11:05

asc-2

3

Scenario 1: Scaling policy (priority policy) + scale-in policy

Auto Scaling strictly filters the ECS instances to be removed based on the Instance Removing Policy. The Priority Policy does not change the result.

In this example, when Custom Policy is selected for the first stage of the Instance Removing Policy, assume that the filtering result of the custom policy is the ECS instances in Hangzhou Zone H and Hangzhou Zone I, whose instance IDs are i-1 and i-3 respectively.

The following table describes the final effect of this instance termination policy.

First stage of the scale-in policy

Second stage of the scale-in policy

Description

Instance ID of the removed instance

Instances Created From Earliest Scaling Configuration

Earliest Instances

First filters the ECS instances that correspond to the earliest scaling configuration, and then selects the earliest created ECS instance from them.

i-1

Most Recent Instances

First filters the ECS instances that correspond to the earliest scaling configuration, and then selects the most recently created ECS instance from them.

i-3

No Policy

Filters the instances that correspond to the earliest scaling configuration, and then randomly selects one ECS instance from them.

i-1, i-2, or i-3

Earliest Instances

-

Removes the earliest created ECS instance.

i-1

Most Recent Instances

-

Removes the most recently created ECS instance.

i-5

Custom Policy

Instances Created From Earliest Scaling Configuration

First filters the ECS instances that match the custom policy rules, and then selects the ECS instance that corresponds to the earliest scaling configuration from them.

i-1

Earliest Instances

First filters the ECS instances that match the custom policy rules, and then selects the earliest created ECS instance from them.

i-1

Most Recent Instances

First filters the ECS instances that match the custom policy rules, and then selects the most recently created ECS instance from them.

i-3

No Policy

Filters the ECS instances that match the custom policy rules, and then randomly selects one ECS instance from them.

i-1 or i-3

Scenario 2: Scaling policy (balanced distribution policy) + scale-in policy

Auto Scaling first filters the zone of the ECS instances based on the Balanced Distribution Policy, and then filters and removes the ECS instance based on the Instance Removing Policy, so that the numbers of ECS instances in the zones of the scaling group are roughly the same after the ECS instance is removed. In this example:

  • Because Hangzhou Zone I has one more ECS instance than Hangzhou Zone H, the filtering result of the balanced distribution policy is the ECS instances in Hangzhou Zone I, whose instance IDs are i-2, i-3, and i-5.

  • When Custom Policy is selected for the first stage of the Instance Removing Policy, assume that the filtering result of the custom policy is the ECS instances in Hangzhou Zone H and Hangzhou Zone I, whose instance IDs are i-1 and i-3 respectively.

The following table describes the final effect of this instance termination policy in combination with the scale-in policy.

First stage of the scale-in policy

Second stage of the scale-in policy

Description

Instance ID of the removed instance

Instances Created From Earliest Scaling Configuration

Earliest Instances

First filters the instances that correspond to the earliest scaling configuration, and then selects the earliest created instance from them.

i-2

Most Recent Instances

First filters the instances that correspond to the earliest scaling configuration, and then selects the most recently created instance from them.

i-3

No Policy

Filters the instances that correspond to the earliest scaling configuration, and then randomly selects one ECS instance from them.

i-2 or i-3

Earliest Instances

-

Removes the earliest created ECS instance.

i-2

Most Recent Instances

-

Removes the most recently created ECS instance.

i-5

Custom Policy

Instances Created From Earliest Scaling Configuration

First filters the ECS instances that match the custom policy rules, and then selects the ECS instance that corresponds to the earliest scaling configuration from them.

i-3

Earliest Instances

First filters the ECS instances that match the custom policy rules, and then selects the earliest created ECS instance from them.

i-3

Most Recent Instances

First filters the ECS instances that match the custom policy rules, and then selects the most recently created ECS instance from them.

i-3

No Policy

Filters the ECS instances that match the custom policy rules, and then randomly selects one ECS instance from them.

i-3

Scenario 3: Scaling policy (cost optimization policy) + scale-in policy

Auto Scaling filters and removes the ECS instance with the highest unit price of vCPUs based on the Cost Optimization Policy. If the scaling group contains multiple instances with the highest unit price of vCPUs, Auto Scaling then filters and removes the ECS instance based on the Instance Removing Policy. In this example:

  • Because the highest unit price of vCPUs is 3USD, the filtering result of the cost optimization policy is the ECS instances whose instance IDs are i-3, i-4, and i-5.

  • When Custom Policy is selected for the first stage of the Instance Removing Policy, assume that the filtering result of the custom policy is the ECS instances in Hangzhou Zone H and Hangzhou Zone I, whose instance IDs are i-1 and i-3 respectively.

The following table describes the final effect of this combined policy in combination with the scale-in policy.

First stage of the scale-in policy

Second stage of the scale-in policy

Description

Instance ID of the removed instance

Instances Created From Earliest Scaling Configuration

Earliest Instances

First filters the instances that correspond to the earliest scaling configuration, and then selects the earliest created instance from them.

i-3

Most Recent Instances

First filters the instances that correspond to the earliest scaling configuration, and then selects the most recently created instance from them.

i-3

No Policy

Filters the instances that correspond to the earliest scaling configuration, and then randomly selects one ECS instance from them.

i-3

Earliest Instances

-

Removes the earliest created ECS instance.

i-3

Most Recent Instances

-

Removes the most recently created ECS instance.

i-5

Custom Policy

Instances Created From Earliest Scaling Configuration

First filters the ECS instances that match the custom policy rules, and then selects the ECS instance that corresponds to the earliest scaling configuration from them.

i-3

Earliest Instances

First filters the ECS instances that match the custom policy rules, and then selects the earliest created ECS instance from them.

i-3

Most Recent Instances

First filters the ECS instances that match the custom policy rules, and then selects the most recently created ECS instance from them.

i-3

No Policy

Filters the ECS instances that match the custom policy rules.

i-3

References