RemoveInstances

更新时间:
复制 MD 格式

If a scaling group is enabled and has no ongoing scaling activities, you can call the RemoveInstances API to remove one or more instances from the group.

Operation description

  • Ensure the following conditions are met before you call this API:
    • The scaling group is in the Active state.

    • The scaling group has no scaling activities in progress.

Note

This API can bypass the cooldown (DefaultCooldown) if the scaling group has no ongoing scaling activities.

  • If an ECS instance is automatically created by Auto Scaling, or is manually added and managed by the scaling group, removing the instance from the scaling group places it in Economical Mode or releases it.

  • If an ECS instance is manually added and not managed by the scaling group, removing the instance from the group does not stop or release it.

  • The call fails if the number of remaining instances would fall below the minimum number of instances (MinSize).

A successful response confirms the Auto Scaling service has accepted the request, but does not guarantee the scaling activity will succeed. You must use the returned ScalingActivityId to check the execution status of the scaling activity.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ess:DetachInstances

update

*ScalingGroup

acs:ess:{#regionId}:{#accountId}:scalinggroup/{#ScalingGroupId}

None None

Request parameters

Parameter

Type

Required

Description

Example

ScalingGroupId

string

Yes

The ID of the scaling group.

asg-bp18p2yfxow2dloq****

RemovePolicy

string

No

Specifies the action to take on removed ECS instances. Valid values:

  • recycle: The ECS instances enter the economical mode.

    Note

    This value takes effect only when the ScalingPolicy parameter of the scaling group is set to recycle.

  • release: The ECS instances are released.

The ScalingPolicy parameter of the CreateScalingGroup operation specifies the reclamation mode of a scaling group. However, the RemovePolicy parameter of the RemoveInstances operation determines the action taken when an instance is removed. For example:

  • If ScalingPolicy is recycle and RemovePolicy is recycle, the ECS instances enter the economical mode.

  • If ScalingPolicy is recycle and RemovePolicy is release, the ECS instances are released.

  • If ScalingPolicy is release and RemovePolicy is recycle, the ECS instances are released.

  • If ScalingPolicy is release and RemovePolicy is release, the ECS instances are released.

Default value: release.

release

DecreaseDesiredCapacity

boolean

No

Specifies whether to decrease the desired capacity of the scaling group. Valid values:

  • true: Decreases the desired capacity of the scaling group by the number of removed instances.

  • false: The desired capacity of the scaling group remains unchanged.

Default value: true.

true

IgnoreInvalidInstance

boolean

No

Specifies whether to ignore invalid instances when you remove multiple instances from a scaling group. Valid values:

  • true: Invalid instances are ignored. If valid instances are removed while invalid ones are present, the scaling activity status is set to Warning. The invalid instances are listed in the scaling activity details.

  • false: The request is rejected and an error is returned if it contains any invalid instances.

Default value: false.

false

InstanceIds

array

Yes

The IDs of the ECS instances to remove.

string

No

The ID of an ECS instance to remove.

i-28wt4****

RegionId

string

No

The region ID of the scaling group.

cn-qingdao

ClientToken

string

No

A client-generated token to ensure request idempotence. This token must be unique for each request, contain only ASCII characters, and not exceed 64 characters. For more information, see How to ensure idempotence.

123e4567-e89b-12d3-a456-42665544****

StopInstanceTimeout

integer

No

The timeout period, in seconds, for an ECS instance to stop during a scale-in. Valid values: 30 to 240.

Note
  • By default, this parameter inherits its value from the scaling group, but you can override it when calling the RemoveInstances operation.

  • This parameter takes effect only during scale-in events where RemovePolicy is set to release.

  • If this parameter is set, the system waits for the specified duration for the instance to stop. The scale-in process continues after the timeout expires, regardless of the instance's state.

  • If this parameter is not set, the system waits until the instance stops before continuing the scale-in process. If the instance fails to stop, the scale-in operation is rolled back and fails.

60

LifecycleHookContext

object

No

The context of the lifecycle hook.

DisableLifecycleHook

boolean

No

Specifies whether to disable all lifecycle hooks for the scaling activity. Valid values:

  • true: Disables all lifecycle hooks.

  • false: Does not disable lifecycle hooks.

false

IgnoredLifecycleHookIds

array

No

A list of lifecycle hook IDs to ignore for the scaling activity.

string

No

The ID of a lifecycle hook to ignore for the scaling activity.

ash-bp14zolna43z266bq***

LifecycleHookResult

string

No

Response elements

Element

Type

Description

Example

object

ScalingActivityId

string

The ID of the scaling activity.

asa-bp175o6f6ego3r2j****

RequestId

string

The ID of the request.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

IgnoredInstances

array<object>

The instances that were not removed and the reasons why they were not removed.

object

InstanceId

string

The ID of the instance that was not removed.

Code

string

The error code that indicates the reason why the instance was not removed.

Message

string

The error message that indicates the reason why the instance was not removed.

Examples

Success response

JSON format

{
  "ScalingActivityId": "asa-bp175o6f6ego3r2j****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
  "IgnoredInstances": [
    {
      "InstanceId": "",
      "Code": "",
      "Message": ""
    }
  ]
}

Error codes

HTTP status code

Error code

Error message

Description

500 InternalError The request processing has failed due to some unknown error, exception or failure.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.