All Products
Search
Document Center

Auto Scaling:RemoveInstances

更新時間:Oct 29, 2024

Removes one or more instances from a scaling group. If your scaling group is enabled and contains no ongoing scaling activities, you can call the RemoveInstances operation to remove instances that you no longer require from the scaling group.

Usage notes

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

    • The scaling group is in the Active state.

    • The scaling group does not have ongoing scaling activities.

If the scaling group does not have ongoing scaling activities, you can call the operation even during the cooldown period.

  • If an Elastic Compute Service (ECS) instance is automatically created by Auto Scaling, or if an ECS instance is manually added to a scaling group and managed by the scaling group, the ECS instance enters Economical Mode or is released when the instance is removed from the scaling group.

  • If an ECS instance is manually added to a scaling group and is not managed by the scaling group, the ECS instance is not stopped or released when the instance is removed from the scaling group.

  • If the difference between the number of existing ECS instances specified by TotalCapacity and the number of ECS instances you want to remove is less than the value of MinSize, the call will fail.

A successful call only indicates that Auto Scaling has accepted the request. It does not guarantee the success of the scaling activity. You can obtain the status of a scaling activity based on the value of ScalingActivityId in the response.

Debugging

OpenAPI Explorer automatically generates 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

RemoveInstances

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

ScalingGroupId

String

Yes

asg-bp18p2yfxow2dloq****

The ID of the scaling group.

RemovePolicy

String

No

release

The action that you want Auto Scaling to perform after ECS instances are removed from the scaling group. Valid values:

  • recycle: puts ECS instances into Economical Mode.

    Note

    This setting takes effect only if you set ScalingPolicy to recycle.

  • release: releases ECS instances.

    ScalingPolicy in the CreateScalingGroup operation specifies the reclaim mode of the scaling group. RemovePolicy in the RemoveInstances operation specifies the specific action on an instance when it is removed. Examples:

    • If you set ScalingPolicy and RemovePolicy to recycle, ECS instances are put into Economical Mode when they are removed.

    • If you set ScalingPolicy to recycle and RemovePolicy to release, ECS instances are released when they are removed.

    • If you set ScalingPolicy to release and RemovePolicy to recycle, ECS instances are released when they are removed.

    • If you set ScalingPolicy and RemovePolicy to release, ECS instances are released when they are removed.

Default value: release.

DecreaseDesiredCapacity

Boolean

No

true

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

  • true: After ECS instances are removed from the scaling group, the expected number of ECS instances in the scaling group decreases.

  • false: After ECS instances are removed from the scaling group, the expected number of ECS instances in the scaling group 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.

InstanceId.N

String

No

i-28wt4****

The ID of ECS instance N that you want to delete. Valid values of N: 1 to 20.

RegionId

String

No

cn-qingdao

The region ID of the scaling group.

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.

StopInstanceTimeout

Integer

No

60

The period of time that is required by ECS instances to enter the Stopped state during the scale-in process. Unit: seconds.

Valid values: 30 to 240.

Note
  • By default, this parameter inherits the value that you specified for the scaling group. You can also change the value when you call the RemoveInstances operation.

  • This parameter takes effect only if you set RemovePolicy to release.

  • If you specify this parameter, the system proceeds with the scale-in process only after the period of time specified by StopInstanceTimeout ends. In this case, the scale-in operation continues regardless of whether or not the ECS instances enter the Stopped state.

  • If you do not specify this parameter, the system proceeds with the scale-in process only after the ECS instances enter the Stopped state. If the ECS instances fail to enter the Stopped state, the scale-in process rolls back, and the scale-in operation fails.

Response parameters

Parameter

Type

Example

Description

ScalingActivityId

String

asa-bp175o6f6ego3r2j****

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=RemoveInstances
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&RemovePolicy=release
&DecreaseDesiredCapacity=true
&IgnoreInvalidInstance=false
&InstanceId=["i-28wt4****"]
&RegionId=cn-qingdao
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&<Common request parameters>

Sample success responses

XML format

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

<RemoveInstancesResponse>
    <ScalingActivityId>asa-bp175o6f6ego3r2j****</ScalingActivityId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</RemoveInstancesResponse>

JSON format

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

{
  "ScalingActivityId" : "asa-bp175o6f6ego3r2j****",
  "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

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 does not exist in the scaling group.

400

InvalidParameter

The specified group does not support the specified RemovePolicy.

The specified scaling group does not support the RemovePolicy setting.

403

Forbidden.Unauthorized

A required authorization for the specified action is not supplied.

Auto Scaling is not authorized to call the operation.

400

IncorrectScalingGroupStatus

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

The scaling group is not in the Active state.

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 scaling group has a scaling activity in progress.

400

IncorrectLoadBalancerStatus

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

The Server Load Balancer (SLB) instance of the scaling group to which the specified scaling rule belongs is not in the Active state.

400

IncorrectDBInstanceStatus

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

The ApsaraDB RDS instance of the scaling group to which the specified scaling rule belongs is not in the Running state.

400

IncorrectCapacity.MinSize

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

The difference between the number of existing ECS instances specified by TotalCapacity and the number of ECS instances that you specified to remove is less than the value of MinSize.