All Products
Search
Document Center

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

Last Updated:Aug 25, 2026

When you create or modify a scaling group, you can set an instance termination policy to control which ECS instances are removed first during a scale-in event. Auto Scaling uses a combination of a scaling policy and a scale-in policy to automatically remove instances that meet the specified criteria. This topic describes how instance termination policies work and provides examples to help you choose the right policies for your use case.

Instance termination policy

An instance termination policy is a combination of a Scaling Policy and a Instance Removing Policy. When Auto Scaling removes an ECS instance from a scaling group, it applies both policies to determine which instance to remove.

Note
  • For details about how to specify an instance termination policy, see Configure a scaling group.

  • If multiple ECS instances in a scaling group match the instance termination policy, Auto Scaling randomly removes one of them.

  • If you do not want to remove manually added ECS instances, see Put an instance into the Protected state.

Scaling policy

A scaling policy determines how to add or remove ECS instances based on criteria such as the zone or the cost of an ECS instance. During a scale-in event, Auto Scaling uses the policy to filter and remove eligible ECS instances from the scaling group. The following scaling policies are available:

  • Priority Policy: The first vSwitch you specify has the highest priority. Auto Scaling first attempts to scale instances in the zone where the highest-priority vSwitch resides. If the scaling activity fails, it automatically proceeds to the zone of the next-highest priority vSwitch.

  • Balanced Distribution Policy: This policy takes effect when a scaling group is associated with multiple vSwitches that are distributed across two or more zones. After a scaling activity, Auto Scaling ensures that ECS instances are distributed evenly across the zones.

  • Cost Optimization Policy: This policy takes effect when you specify multiple instance types in the scaling configuration. During a scale-out event, Auto Scaling creates ECS instances with the lowest unit price of vCPUs first. During a scale-in event, Auto Scaling removes ECS instances with the highest unit price of vCPUs first.

    Note

    If you specify multiple instance types for preemptible instances in a scaling configuration, Auto Scaling creates the corresponding preemptible instances first. If preemptible instances cannot be created, for example, due to insufficient inventory, Auto Scaling automatically attempts to create pay-as-you-go ECS instances.

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

Scale-in policy

A scale-in policy determines which eligible ECS instances to remove from a scaling group. You can configure a scale-in policy with one or two steps:

  • If you configure a one-step policy, Auto Scaling filters instances based on the single criterion you define.

  • If you configure a two-step policy, Auto Scaling first filters instances based on the first criterion and then applies the second criterion. You cannot select the same option for both steps.

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 scenarios use the ECS instances described in the table below. The examples show how Auto Scaling removes one ECS instance from the scaling group based on different combinations of a Scaling Policy and a Instance Removing Policy.

Note

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

Instance ID

Zone

Added at

Scaling configuration

(asc-1 was added first)

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: Priority policy + scale-in policy

Auto Scaling strictly follows the Instance Removing Policy to select an ECS instance for removal. The Priority Policy does not affect the outcome.

In this example, the first step of the Instance Removing Policy is set to Custom Policy. The custom policy identifies instances i-1 (in Hangzhou Zone H) and i-3 (in Hangzhou Zone I) as candidates for removal. The following table shows the final outcome of this instance termination policy.

First step of scale-in policy

Second step of scale-in policy

Description

Removed instance ID

Instances Created From Earliest Scaling Configuration

Earliest Instances

Auto Scaling first identifies instances from the earliest scaling configuration (asc-1), then removes the earliest created instance from that set.

i-1

Most Recent Instances

Auto Scaling first identifies instances from the earliest scaling configuration (asc-1), then removes the most recently created instance from that set.

i-3

No Policy

Auto Scaling identifies instances from the earliest scaling configuration (asc-1) and then randomly removes one instance from that set.

  • i-1

  • i-2

  • i-3

Earliest Instances

-

Removes the earliest created ECS instance in the group.

i-1

Most Recent Instances

-

Removes the most recently created ECS instance in the group.

i-5

Custom Policy

Instances Created From Earliest Scaling Configuration

Auto Scaling first identifies instances that match the custom policy (i-1, i-3), then removes the one from the earliest scaling configuration.

i-1

Earliest Instances

Auto Scaling first identifies instances that match the custom policy (i-1, i-3), then removes the earliest created one.

i-1

Most Recent Instances

Auto Scaling first identifies instances that match the custom policy (i-1, i-3), then removes the most recently created one.

i-3

No Policy

Auto Scaling identifies instances that match the custom policy (i-1, i-3) and then randomly removes one.

  • i-1

  • i-3

Scenario 2: Balanced distribution policy + scale-in policy

Auto Scaling first applies the Balanced Distribution Policy to select a zone for removal, and then applies the Instance Removing Policy to remove an instance. This ensures the number of instances remains balanced across zones after the scale-in activity. In this example:

  • Because Hangzhou Zone I has more ECS instances than Hangzhou Zone H, the balanced distribution policy identifies the instances in Hangzhou Zone I as candidates for removal. The candidates are i-2, i-3, and i-5.

  • If the first step of the Instance Removing Policy is set to Custom Policy, we assume the policy identifies instances i-1 (from Hangzhou Zone H) and i-3 (from Hangzhou Zone I) as candidates.

The following table shows the final outcome when combining these policies.

First step of scale-in policy

Second step of scale-in policy

Description

Removed instance ID

Instances Created From Earliest Scaling Configuration

Earliest Instances

Among the candidates in Zone I (i-2, i-3, i-5), this policy selects instances from the earliest configuration (i-2, i-3) and removes the one created earliest.

i-2

Most Recent Instances

Among the candidates in Zone I (i-2, i-3, i-5), this policy selects instances from the earliest configuration (i-2, i-3) and removes the most recently created one.

i-3

No Policy

Among the candidates in Zone I (i-2, i-3, i-5), this policy selects instances from the earliest configuration (i-2, i-3) and randomly removes one.

  • i-2

  • i-3

Earliest Instances

-

Among the candidates in Zone I (i-2, i-3, i-5), this policy removes the one created earliest.

i-2

Most Recent Instances

-

Among the candidates in Zone I (i-2, i-3, i-5), this policy removes the most recently created one.

i-5

Custom Policy

Instances Created From Earliest Scaling Configuration

The intersection of candidates from the balanced distribution policy (i-2, i-3, i-5) and custom policy (i-1, i-3) is {i-3}. This policy has no further effect.

i-3

Earliest Instances

The intersection of candidates from the balanced distribution policy (i-2, i-3, i-5) and custom policy (i-1, i-3) is {i-3}. This policy has no further effect.

i-3

Most Recent Instances

The intersection of candidates from the balanced distribution policy (i-2, i-3, i-5) and custom policy (i-1, i-3) is {i-3}. This policy has no further effect.

i-3

No Policy

The intersection of candidates from the balanced distribution policy (i-2, i-3, i-5) and custom policy (i-1, i-3) is {i-3}. The instance is removed.

i-3

Scenario 3: Cost optimization policy + scale-in policy

Auto Scaling first applies the Cost Optimization Policy to remove the ECS instance with the highest unit price of vCPUs. If multiple instances share the highest price, Auto Scaling then applies the Instance Removing Policy to select which one to remove. In this example:

  • The highest unit price of vCPUs is 3 USD. The cost optimization policy identifies instances i-3, i-4, and i-5 as candidates for removal.

  • If the first step of the Instance Removing Policy is set to Custom Policy, we assume the policy identifies instances i-1 (from Hangzhou Zone H) and i-3 (from Hangzhou Zone I) as candidates.

The following table shows the final outcome when combining these policies.

First step of scale-in policy

Second step of scale-in policy

Description

Removed instance ID

Instances Created From Earliest Scaling Configuration

Earliest Instances

Among the most expensive instances (i-3, i-4, i-5), this policy selects the one from the earliest configuration (i-3) and removes it.

i-3

Most Recent Instances

Among the most expensive instances (i-3, i-4, i-5), this policy selects the one from the earliest configuration (i-3) and removes it.

i-3

No Policy

Among the most expensive instances (i-3, i-4, i-5), this policy selects the one from the earliest configuration (i-3) and removes it.

i-3

Earliest Instances

-

Among the most expensive instances (i-3, i-4, i-5), this policy removes the one created earliest.

i-3

Most Recent Instances

-

Among the most expensive instances (i-3, i-4, i-5), this policy removes the most recently created one.

i-5

Custom Policy

Instances Created From Earliest Scaling Configuration

The intersection of the most expensive instances (i-3, i-4, i-5) and custom policy candidates (i-1, i-3) is {i-3}. The instance is removed.

i-3

Earliest Instances

The intersection of the most expensive instances (i-3, i-4, i-5) and custom policy candidates (i-1, i-3) is {i-3}. The instance is removed.

i-3

Most Recent Instances

The intersection of the most expensive instances (i-3, i-4, i-5) and custom policy candidates (i-1, i-3) is {i-3}. The instance is removed.

i-3

No Policy

Removes the instance that matches both the cost optimization and custom policies.

i-3

Related topics