All Products
Search
Document Center

Auto Scaling:DetachInstances

Last Updated:Oct 27, 2023

Removes one or more Elastic Compute Service (ECS) instances, elastic container instances, or managed instances from a scaling group.

Usage notes

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

    • The specified scaling group is enabled.

    • The specified scaling group does not have any scaling activities in progress.

      Note

      If the specified scaling group does not have any scaling activities in progress, the operation can bypass the cooldown period of the scaling group and immediately trigger scaling activities.

  • When you use this operation, take note of the following items:

    • After you remove an ECS instance, an elastic container instance, or a managed instance from the specified scaling group, the instance can run independently. You can also call the AttachInstances operation to add the instance to another scaling group.

    • After you call this operation to remove an ECS instance, an elastic container instance, or a managed instance from the specified scaling group, the instance is not stopped or released.

    • A successful call only means that Auto Scaling accepts the request, and does not mean that the scaling activity can succeed. You can obtain the status of a scaling activity based on the return value of ScalingActivityId.

    • After you remove a specific number of ECS instances, elastic container instances, or managed instances from the specified scaling group, the remaining number of instances must be equal to or greater than the minimum number of instances that must be contained in the scaling group. Otherwise, the operation fails, and an error is reported.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

DetachInstances

The operation that you want to perform. Set the value to DetachInstances.

ScalingGroupId

String

Yes

asg-bp1igpak5ft1flyp****

The ID of the scaling group.

DecreaseDesiredCapacity

Boolean

No

true

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

  • true: After you call this operation to remove a specific number of ECS instances, elastic container instances, or managed instances from the specified scaling group, the expected number of instances decreases.

  • false: After you call this operation to remove a specific number of ECS instances, elastic container instances, or managed instances from the specified scaling group, the expected number of instances remains unchanged.

Default value: true.

DetachOption

String

No

both

Specifies whether to remove the ECS instances or elastic container instances from the default server group and vServer groups of the Server Load Balancer (SLB) instance that is associated with the scaling group, and whether to remove the IP addresses of the instances from the IP address whitelist of the ApsaraDB RDS instance that is associated with the scaling group.

If you set this parameter to both, the instances are removed from the default server group and vServer groups of the associated SLB instance, and the IP addresses of the instances are removed from the IP address whitelist of the associated ApsaraDB RDS instance.

Note

This parameter is unavailable in the case that you call this operation to remove a specific number of managed instances from the specified scaling group.

InstanceId.N

String

No

i-bp109k5j3dum1ce6****

The ID of ECS instance N, elastic container instance N, or managed instance N that you want to remove from the specified scaling group. Valid values of N: 1 to 20.

Examples:

  • Sample ECS instance ID: i-bp109k5j3dum1ce6****.

  • Sample elastic container instance ID: eci-bp17gw49eu09yiwm****.

  • Sample managed instance ID: mi-d23fsd******.

    Note

    You can call this operation to remove only instances of the same type at a time.

LifecycleHook

Boolean

No

false

Specifies whether to trigger a lifecycle hook when you call this operation. Valid values:

  • true

  • false

    Note

    This parameter is unavailable in the case that you call this operation to remove a specific number of managed instances from the specified scaling group.

Default value: false.

ClientToken

String

No

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

The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but you must 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 the idempotence.

Response parameters

Parameter

Type

Example

Description

ScalingActivityId

String

asa-bp1gbswjhjrw8tko****

The ID of the scaling activity.

RequestId

String

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

The ID of the request.

Examples

Sample requests

http(s)://ess.aliyuncs.com/?Action=DetachInstances
&ScalingGroupId=asg-bp1igpak5ft1flyp****
&DecreaseDesiredCapacity=true
&DetachOption=both
&InstanceId=["i-bp109k5j3dum1ce6****"]
&LifecycleHook=false
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<DetachInstancesResponse>
    <ScalingActivityId>asa-bp1gbswjhjrw8tko****</ScalingActivityId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</DetachInstancesResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

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

Error codes

For a list of error codes, see Service error codes.

Http status code

Error code

Error message

Description

400

IncorrectScalingGroupStatus

The current status of the specified scaling group does not support this action.

The specified scaling group is not enabled.

400

ScalingActivityInProgress

You cannot delete a scaling group or launch a new scaling activity while there is a scaling activity in progress for the specified scaling group.

The specified scaling group has a scaling activity in progress.

400

IncorrectLoadBalancerStatus

The current status of the specified load balancer does not support this action.

The specified SLB instance is not in the Active state.

400

IncorrectDBInstanceStatus

The current status of DB instance "XXX" does not support this action.

The specified ApsaraDB RDS instance is not in the Running state.

400

IncorrectCapacity.MinSize

To remove the instances, the total capacity will be lesser than the MinSize.

The number of ECS instances or elastic container instances in the scaling group is less than the value of MinSize if the specified number of instances are removed.

403

Forbidden.Unauthorized

A required authorization for the specified action is not supplied.

You are not authorized to call this operation.

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The specified scaling group does not exist.

404

InvalidInstanceId.NotFound

Instance "XXX" does not exist.

The specified ECS instance or elastic container instance does not exist within the Alibaba Cloud account.