You can call this operation to remove one or more ECS instances from one scaling group.

Description

After ECS instances are removed, the instances are independent of the scaling group. You can call the AttachInstances operation to add the instance to another scaling group.

Removing an ECS instance does not stop or release it. You can manually stop or release an ECS instance as needed.

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

  • The specified scaling group must be enabled.
  • The specified scaling group must not have any scaling activities in progress.

If the specified scaling group does not have any scaling activities in progress, the operation can be immediately executed without the need to wait for the cooldown period to expire.

When this operation is called successfully, Auto Scaling receives the request. The scaling activity can be triggered, but it is not guaranteed that the scaling activity can be successfully run. You can use the ScalingActivityId parameter returned in the response to query the status of the scaling activity.

The difference between the number of ECS instances currently in the specified scaling group and the number of ECS instances to be removed must not be less than MinSize.

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
InstanceId.N RepeatList Yes i-28wt4****

The IDs of one or more ECS instances. Valid values of N: 1 to 20.

ScalingGroupId String Yes AG6CQdPU8OKdwLjgZcJ****

The ID of the scaling group.

Action String No DetachInstances

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

DecreaseDesiredCapacity Boolean No true

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

  • true: The expected number of instances decreases accordingly after the ECS instances are removed from the scaling group.
  • false: The expected number of instances remains unchanged after the ECS instances are removed from the scaling group.

Default value: true

Response parameters

Parameter Type Example Description
RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The ID of the request.

ScalingActivityId String asa-****

The ID of the scaling activity.

Examples

Sample requests

http://ess.aliyuncs.com/?Action=DetachInstances
&ScalingGroupId=AG6CQdPU8OKdwLjgZcJ****
&InstanceId.1=i-28wt4****
&<Common request parameters>

Sample success responses

XML format

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

JSON format

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

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 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 error message returned because 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 error message returned because the SLB instance of the specified scaling group is not active.

400

IncorrectDBInstanceStatus

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

The error message returned because the RDS instance of the specified scaling group is not running.

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 to be removed will leave the number of ECS instances in the specified scaling group less than MinSize.

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.