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

Description

After ECS instances or elastic container instances are removed from a scaling group, you can call the AttachInstances operation to add the ECS instances or elastic container instances that are removed from the scaling group to other scaling groups.

After you remove an ECS instance or elastic container instance by calling the DetachInstances operation, the instance is not stopped or released.

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

  • The specified scaling group is enabled.
  • No scaling activities in the specified scaling group are in progress.

If no scaling activities in the specified scaling group are in progress, the operation can immediately trigger scaling activities without the need to wait for the cooldown time to expire.

A successful call indicates only that Auto Scaling accepts the request. However, the scaling activity may still fail. You can obtain the status of a scaling activity based on the return value of the ScalingActivityId parameter.

The number of ECS instances or elastic container instances in a scaling group after you remove a specific number of instances from the scaling group must be equal to or greater than the value of the MinSize parameter. Otherwise, an error is reported when you call the DetachInstances operation.

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 adjust the expected number of instances in the scaling group. Valid values:

  • true: After a specific number of instances are removed from the scaling group, the expected number of instances in the scaling group decreases.
  • false: After a specific number of instances are removed from the scaling group, the expected number of instances in the scaling group remains unchanged.

Default value: true.

DetachOption String No both

Specifies whether to remove the instances from the default server groups 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 whitelist that manages access to 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 sever groups and vServer groups of the associated SLB instance, and the IP addresses of the instances are removed from the whitelist that manages access to the associated ApsaraDB RDS instance.

LifecycleHook Boolean No false

Specifies whether to trigger the lifecycle hook for the scaling group when you remove instances from the scaling group. Valid values:

  • true
  • false

Default value: false.

InstanceId.N String Yes i-bp109k5j3dum1ce6****

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

Examples:

  • The ID of the ECS instance that you want to remove is i-bp109k5j3dum1ce6****.
  • The ID of the elastic container instance that you want to remove is eci-bp17gw49eu09yiwm****.

Response parameters

Parameter Type Example Description
ScalingActivityId String asa-bp1gbswjhjrw8tko****

The ID of the scaling activity.

RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

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
&<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-A3DC0DE3C83E</RequestId>
</DetachInstancesResponse>

JSON format

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

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

Error codes

For a list of error codes, visit the API Error Center.

HTTP status code

Error code

Error message

Description

400

IncorrectScalingGroupStatus

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

The error message returned because the specified scaling group is disabled.

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 error message returned because a scaling activity in the specified scaling group is in progress.

400

IncorrectLoadBalancerStatus

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

The error message returned because 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 error message returned because 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 error message returned because the number of instances in the scaling group is less than the value of the MinSize parameter if the specified number of instances are removed.

403

Forbidden.Unauthorized

A required authorization for the specified action is not supplied.

The error message returned because you are not authorized to call this operation.

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The error message returned because the specified scaling group does not exist.

404

InvalidInstanceId.NotFound

Instance "XXX" does not exist.

The error message returned because the specified instance does not exist within the Alibaba Cloud account.