All Products
Search
Document Center

Auto Scaling:DetachInstances

Last Updated:Sep 10, 2026

Removes one or more ECS instances from a scaling group.

Operation description

Operation description

  • Before you call this operation, make sure that the following conditions are met:

    • The scaling group is in the Enabled state.

    • No scaling activity is in progress in the scaling group.

      Note

      If no scaling activity is in progress in the scaling group, this operation can bypass the cooldown time and directly trigger a scaling activity.

  • Take note of the following items:

    • After an ECS instance, an elastic container instance, or a managed instance is removed from a scaling group, the instance continues to exist independently. You can call the AttachInstances operation to add the ECS instance, elastic container instance, or managed instance to another scaling group.

    • Calling this operation to remove an ECS instance, an elastic container instance, or a managed instance does not stop or release the instance.

    • After the operation is called, it only indicates that Auto Scaling has accepted the request. A scaling activity can be triggered, but the success of the scaling activity is not guaranteed. You must check the status of the scaling activity based on the returned ScalingActivityId.

    • The number of ECS instances, elastic container instances, or managed instances in the scaling group minus the number of instances being removed cannot be less than the minimum number of instances (MinSize) in the scaling group. Otherwise, an error is returned.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request parameters

Parameter

Type

Required

Description

Example

ScalingGroupId

string

Yes

The ID of the scaling group.

asg-bp1igpak5ft1flyp****

DecreaseDesiredCapacity

boolean

No

Specifies whether to modify the expected number of instances. Valid values:

  • true: After the ECS instances, elastic container instances, or managed instances are removed from the scaling group, the expected number of instances is decreased by the corresponding amount.

  • false: After the ECS instances, elastic container instances, or managed instances are removed from the scaling group, the expected number of instances remains unchanged.

Default value: true.

true

IgnoreInvalidInstance

boolean

No

Specifies whether to ignore invalid instances when removing a batch of instances from the scaling group. Valid values:

  • true: Invalid instances are ignored when a batch of instances is removed from the scaling group.

    If a batch of instances contains invalid instances (for example, instances whose instance status is Pending) and the valid instances are successfully removed, the scaling activity execute status is displayed as Warning. You can view the invalid instances in the scaling activity details.

  • false: Invalid instances are not ignored when a batch of instances is removed from the scaling group.

    If a batch of instances contains invalid instances (for example, instances whose instance status is Pending), an error is returned.

Default value: false.

false

DetachOption

string

No

Specifies whether to stop using ECS instances or elastic container instances as backend servers of the associated load balancing instance (that is, remove the ECS instances or elastic container instances from the default server group and virtual server group of the load balancing instance), and whether to remove the ECS instances or elastic container instances from the access whitelist of the associated ApsaraDB RDS instance.

both: removes the ECS instances or elastic container instances from the default server group and virtual server group of the load balancing instance, and removes the ECS instances or elastic container instances from the access whitelist of the ApsaraDB RDS instance.

Note

Settings for this parameter are not supported when managed instances are removed from the scaling group.

both

InstanceId

array

Yes

The ID of the ECS instance, elastic container instance, or managed instance to be removed.

i-bp109k5j3dum1ce6****

string

No

Instance ID of the ECS instance, elastic container instance, or managed instance to be removed. Valid values of N: 1 to 20.

Examples:

  • Instance ID of the ECS instance to be removed is i-bp109k5j3dum1ce6****.

  • Instance ID of the elastic container instance to be removed is eci-bp17gw49eu09yiwm****.

  • Instance ID of the managed instance to be removed is mi-d23fsd******.

Note

Only one type of instance can be removed in a single request.

i-bp109k5j3dum1ce6****

LifecycleHook

boolean

No

Specifies whether to trigger the scale-in lifecycle hook when ECS instances or elastic container instances are removed from the scaling group. Valid values:

  • true: triggers the lifecycle hook.

  • false: does not trigger the lifecycle hook.

Note

This parameter is not supported when managed instances are removed from the scaling group.

Default value: false.

false

ClientToken

string

No

The client token that is used to ensure the idempotence of the request.

You can use the client to generate the token, but make sure that the token is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

123e4567-e89b-12d3-a456-42665544****

Response elements

Element

Type

Description

Example

object

ScalingActivityId

string

The ID of the scaling activity.

asa-bp1gbswjhjrw8tko****

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

Examples

Success response

JSON format

{
  "ScalingActivityId": "asa-bp1gbswjhjrw8tko****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}

Error codes

HTTP status code

Error code

Error message

Description

500 InternalError The request processing has failed due to some unknown error, exception or failure.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.