All Products
Search
Document Center

Auto Scaling:Set the instance termination policy for a scaling group

Last Updated:Apr 02, 2026

When a scaling group scales in, Auto Scaling uses two policies together to decide which Elastic Compute Service (ECS) instance to remove: a scaling policy and a scale-in policy. The scaling policy narrows the candidate pool by zone or cost; the scale-in policy picks the specific instance to remove from that pool.

If multiple instances meet the requirements defined in the policy combination, Auto Scaling removes one at random. To prevent a manually added instance from being removed, put it into the Protected state.

How scale-in selection works

Scale-in selection follows two stages, in order:

  1. Scaling policy — filters the candidate pool to a subset of instances (by zone balance, cost, or priority).

  2. Scale-in policy — selects one instance from that subset based on creation time or a custom function.

The examples in this topic show the result of each policy combination, so you can predict which instance Auto Scaling removes in your own scaling group.

Scaling policies

Set the scaling policy when you create or modify a scaling group. It controls how Auto Scaling distributes and removes instances across zones.

Priority policy

Auto Scaling scales in the zone of the highest-priority vSwitch first. If scaling fails there, it moves to the vSwitch with the next highest priority.

During scale-in, the priority policy does not filter by zone — the scale-in policy determines which instance is removed. See Scenario 1 for examples.

Balanced distribution policy

Requires the scaling group to be associated with multiple vSwitches in different zones. After each scale-in, the distribution of instances across zones stays balanced.

During scale-in, Auto Scaling first identifies the zone with the most instances, then applies the scale-in policy to choose which instance to remove from that zone. See Scenario 2 for examples.

Cost optimization policy

Requires the scaling configuration to have multiple instance types. During scale-in, Auto Scaling removes the instance with the highest vCPU unit price first. When multiple instances share the highest price, the scale-in policy decides which one to remove. See Scenario 3 for examples.

If the scaling configuration includes multiple preemptible instance types, Auto Scaling creates preemptible instances first during scale-out. Pay-as-you-go instances are created only when preemptible instances are unavailable due to insufficient inventory.

Custom combination policy

Lets you define a custom ratio of pay-as-you-go to preemptible instances, balance instances across zones, and select specific instance types. Configure the policy in the Auto Scaling console.

Scale-in policies

The scale-in policy selects a specific instance from the candidates the scaling policy produces. Configure one or two steps in the Auto Scaling console:

  • One step: Auto Scaling filters instances using that step's criteria and removes the result (or a random instance if multiple match).

  • Two steps: Auto Scaling applies the first step, then applies the second step to the result of the first.

Available options for each step:

Option What Auto Scaling removes
Instances created from earliest scaling configuration The instance created using the earliest scaling configuration or launch template. Manually added instances have no associated configuration, so they are excluded unless no other instances remain — at which point manually added instances are removed randomly.
Earliest instances The instance created at the earliest point in time.
Most recent instances The instance created at the most recent point in time.
Custom policy The instance selected by a custom policy containing a service, version, and function (configured using Function Compute).
No policy *(second step only)* No additional filtering; Auto Scaling removes a random instance from the first step's result.
The order in which a launch template was added to a scaling group determines which is "earliest" — not the template version number. For example, if lt-foress V2 was specified when the scaling group was created, and then replaced with lt-foress V1 when the group was modified, Auto Scaling treats lt-foress V2 as the earliest template.

Examples

The following examples use five instances in a single scaling group. The examples show which instance Auto Scaling removes for each policy combination.

The instance data below is for illustration only. Actual values in the Auto Scaling console take precedence.
Instance ID Zone Created at Scaling configuration vCPU unit price (USD)
i-1 Hangzhou Zone H May 17, 2021, 11:05:00 asc-1 (earliest) 1
i-2 Hangzhou Zone I May 18, 2021, 11:05:00 asc-1 (earliest) 2
i-3 Hangzhou Zone I May 19, 2021, 11:05:00 asc-1 (earliest) 3
i-4 Hangzhou Zone H May 20, 2021, 11:05:00 asc-2 3
i-5 Hangzhou Zone I May 21, 2021, 11:05:00 asc-2 3

Scenario 1: Priority policy + scale-in policy

The priority policy does not filter by zone during scale-in, so the scale-in policy alone determines which instance is removed. All five instances are candidates.

In the custom policy examples below, the custom policy targets instances in Hangzhou Zone I and Hangzhou Zone H with IDs i-1 and i-3.

First step Second step Why this instance is selected Removed instance
Instances created from earliest scaling configuration Earliest instances asc-1 created i-1, i-2, and i-3. Of these, i-1 was created first. i-1
Most recent instances asc-1 created i-1, i-2, and i-3. Of these, i-3 was created last. i-3
No policy asc-1 created i-1, i-2, and i-3. No further filtering — one is removed at random. i-1, i-2, or i-3 (random)
Earliest instances No zone filter; i-1 was created first across all instances. i-1
Most recent instances No zone filter; i-5 was created last across all instances. i-5
Custom policy Instances created from earliest scaling configuration Custom policy selects i-1 and i-3. Of these, i-1 was created using asc-1, which is the earliest configuration. i-1
Earliest instances Custom policy selects i-1 and i-3. Of these, i-1 was created first. i-1
Most recent instances Custom policy selects i-1 and i-3. Of these, i-3 was created last. i-3
No policy Custom policy selects i-1 and i-3. No further filtering — one is removed at random. i-1 or i-3 (random)

Scenario 2: Balanced distribution policy + scale-in policy

Hangzhou Zone I has three instances (i-2, i-3, i-5) and Hangzhou Zone H has two (i-1, i-4). Zone I has one more instance, so Auto Scaling targets Zone I to restore balance. The candidates are i-2, i-3, and i-5.

Exception: if a custom policy is configured in the first step, it selects i-3 (Zone I) from the custom policy's target set of i-1 and i-3 — because only i-3 is in the over-represented zone.

First step Second step Why this instance is selected Removed instance
Instances created from earliest scaling configuration Earliest instances Zone I candidates: i-2, i-3, i-5. Of the asc-1 instances (i-2, i-3), i-2 was created first. i-2
Most recent instances Zone I candidates: i-2, i-3, i-5. Of the asc-1 instances (i-2, i-3), i-3 was created last. i-3
No policy Zone I candidates: i-2, i-3, i-5. asc-1 instances in Zone I are i-2 and i-3. No further filtering — one is removed at random. i-2 or i-3 (random)
Earliest instances Zone I candidates: i-2, i-3, i-5. i-2 was created first among them. i-2
Most recent instances Zone I candidates: i-2, i-3, i-5. i-5 was created last among them. i-5
Custom policy Instances created from earliest scaling configuration Custom policy targets i-1 and i-3; only i-3 is in Zone I. i-3 is removed. i-3
Earliest instances Custom policy targets i-1 and i-3; only i-3 is in Zone I. i-3 is removed. i-3
Most recent instances Custom policy targets i-1 and i-3; only i-3 is in Zone I. i-3 is removed. i-3
No policy Custom policy targets i-1 and i-3; only i-3 is in Zone I. i-3 is removed. i-3

Scenario 3: Cost optimization policy + scale-in policy

The highest vCPU unit price among all instances is USD 3. Auto Scaling targets i-3, i-4, and i-5 — all priced at USD 3.

Exception: if a custom policy is configured in the first step, it selects i-1 (Zone H) and i-3 (Zone I). Of these, only i-3 has the highest price (USD 3), so i-3 is always removed when a custom policy applies.

First step Second step Why this instance is selected Removed instance
Instances created from earliest scaling configuration Earliest instances Highest-price candidates: i-3, i-4, i-5. Of the asc-1 instances (i-3), i-3 is the only match. i-3
Most recent instances Highest-price candidates: i-3, i-4, i-5. Of the asc-1 instances (i-3), i-3 is the only match. i-3
No policy Highest-price candidates: i-3, i-4, i-5. Only i-3 was created using asc-1. i-3
Earliest instances Highest-price candidates: i-3, i-4, i-5. i-3 was created first among them. i-3
Most recent instances Highest-price candidates: i-3, i-4, i-5. i-5 was created last among them. i-5
Custom policy Instances created from earliest scaling configuration Custom policy selects i-1 and i-3. Of these, only i-3 has the highest price. i-3
Earliest instances Custom policy selects i-1 and i-3. Of these, only i-3 has the highest price. i-3
Most recent instances Custom policy selects i-1 and i-3. Of these, only i-3 has the highest price. i-3
No policy Custom policy selects i-1 and i-3. Of these, only i-3 has the highest price. i-3

What's next