All Products
Search
Document Center

Auto Scaling:DetachInstances

更新時間:Jun 18, 2024

Removes instances from a scaling group. If your scaling group is in the Enabled state and contains no ongoing scaling activities, you can call the DetachInstances operation to remove one or more Elastic Compute Service (ECS) instances, elastic container instances, or Alibaba Cloud-managed third-party instances from the scaling group.

Usage notes

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

    • The specified scaling group is enabled.

    • The specified scaling group does not have any ongoing scaling activities.

      Note

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

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

    • After you remove an ECS instance, an elastic container instance, or an Alibaba Cloud-managed third-party 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 an Alibaba Cloud-managed third-party instance from the specified scaling group, the instance is not stopped or released.

    • A successful call only indicates that Auto Scaling has accepted the request, but it does not guarantee the success of the scaling activity. 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 Alibaba Cloud-managed third-party 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 will fail, and an error will be 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 Alibaba Cloud-managed third-party 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 Alibaba Cloud-managed third-party instances from the specified scaling group, the expected number of instances remains unchanged.

Default value: true.

IgnoreInvalidInstance

Boolean

No

false

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

  • true: ignores invalid instances.

    If the batch of instances includes invalid instances, such as instances in the Adding state, and the valid instances are successfully removed from the scaling group, the corresponding scaling activity will enter the Warning state. You can go to the scaling activity details page to view the invalid instances.

  • false: does not ignore invalid instances.

    If the batch of instances includes invalid instances, such as instances in the Adding state, an error will be reported.

Default value: false.

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 attached Server Load Balancer (SLB) instances, and whether to remove their private IP addresses from the IP address whitelists of the attached ApsaraDB RDS instances.

If you set this parameter to both, the instances are removed from the default sever groups and vServer groups of the attached SLB instances, and their IP addresses are removed from the IP address whitelists of the attached ApsaraDB RDS instances.

Note

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

InstanceId.N

String

No

i-bp109k5j3dum1ce6****

The ID of ECS instance N, elastic container instance N, or Alibaba Cloud-managed third-party instance N that you want to remove from the 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 Alibaba Cloud-managed third-party instances from the 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 Ensure 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 request ID.

Examples

Sample requests

http(s)://ess.aliyuncs.com/?Action=DetachInstances
&ScalingGroupId=asg-bp1igpak5ft1flyp****
&DecreaseDesiredCapacity=true
&IgnoreInvalidInstance=false
&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 an ongoing scaling activity.

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 within the Alibaba Cloud account.

404

InvalidInstanceId.NotFound

Instance "XXX" does not exist.

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