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

Description

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

After you remove an ECS instance by calling the DetachInstances operation, the ECS 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 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 the ScalingActivityId parameter.

The difference between the number of existing ECS instances in the specified scaling group and the number of ECS instances to be removed must not be less than the MinSize value. Otherwise, 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 adjust the expected number of ECS instances in the scaling group. Valid values:

  • true: After ECS instances are removed from a scaling group, the expected number of ECS instances in the scaling group decreases.
  • false: After ECS instances are removed from a 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 ECS instance from the default server groups and vServer groups of the Server Load Balancer (SLB) instance associated with the scaling group, and whether to remove the IP address of the ECS instance from the whitelist that manages access to the ApsaraDB RDS instance associated with the scaling group.

If you set the value to both, the ECS instance is removed from the default sever groups and vServer groups of the associated SLB instance, and the IP address of the ECS instance is removed from the whitelist that manages access to the associated ApsaraDB RDS instances.

LifecycleHook Boolean No false

Specifies whether to trigger the lifecycle hook for the scaling group to which the ECS instances are being added. Valid values:

  • true: triggers the lifecycle hook for the scaling group to which the ECS instances are being added.
  • false: does not trigger the lifecycle hook for the scaling group to which the ECS instances are being added.

Default value: false.

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

The ID of ECS instance N to be removed. Valid values of N: 1 to 20.

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

https://ess.aliyuncs.com/?Action=DetachInstances
&ScalingGroupId=asg-bp1igpak5ft1flyp****
&InstanceId.1=i-bp109k5j3dum1ce6****
&<Common request parameters>

Sample success responses

XML format

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

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

JSON format

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

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

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 ECS instances in the scaling group is less than the MinSize value if the specified number of ECS 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 ECS instance does not exist.