All Products
Search
Document Center

Auto Scaling:AttachInstances

Last Updated:Apr 08, 2024

Adds instances to a scaling group to provide services or restarts Elastic Compute Service (ECS) instances stopped in Economical Mode to provide services. You can call the AttachInstances operation to add ECS instances, elastic container instances, or third-party instances managed by Alibaba Cloud to your scaling group to provide services. You can also call this operation to restart ECS instances stopped in Economical Mode in your scaling group to provide services.

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 has no ongoing scaling activities.

  • If you want to add ECS instances or elastic container instances to the scaling group, make sure that the following requirements are met:

    • The instances reside in the same region as the scaling group.

    • The instances are in the Running state.

    • The instances cannot belong to another scaling group.

    • The instances are billed on a subscription or pay-as-you-go basis, or the instances are preemptible instances.

    • If VswitchID is specified for the scaling group, the instances that are in the classic network or those that are not in the same virtual private cloud (VPC) as the specified vSwitch cannot be added to the scaling group.

    • If VswitchID is not specified for the scaling group, the instances that are in VPCs cannot be added to the scaling group.

  • If you want to add managed instances to the scaling group, make sure that the following requirements are met:

    • The managed instances reside in the same region as the scaling group.

    • The managed instances cannot belong to another scaling group.

    • The managed instances do not support the lifecycle hook, attachment to Server Load Balancer (SLB), and health check features.

    • After you add a managed instance to a scaling group of the ECS type, the scaling group does not manage the lifecycle of the managed instance.

    • You can only manually add managed instances to or remove managed instances from a scaling group. The managed instances that are removed from a scaling group are not released.

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

    • If the scaling group has no ongoing scaling activities, the operation can trigger scaling activities without waiting for the cooldown period to expire.

    • A successful call indicates that Auto Scaling accepts the request. However, the scaling activity may still fail. You can obtain the status of a scaling activity based on the return value of ScalingActivityId.

    • The total number of instances in the scaling group must be less than or equal to the maximum number of instances that can be contained in the scaling group after you call the operation. Otherwise, the operation fails.

    • The ECS instances, elastic container instances, or managed instances that you manually add to the scaling group by calling the operation are not associated with the active scaling configuration of the scaling group.

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

AttachInstances

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

ScalingGroupId

String

Yes

asg-bp18p2yfxow2dloq****

The ID of the scaling group.

Entrusted

Boolean

No

false

Specifies whether to allow the scaling group to manage the lifecycles of the instances that are manually added. Valid values:

  • true: allows the scaling group to manage the lifecycles of the instances that are manually added in a similar manner in which it manages the lifecycles of instances that are automatically created. When the instances are removed from the scaling group, the instances are released. This rule does not apply to instances that are removed from scaling groups by calling the DetachInstances operation.

  • false: does not allow the scaling group to manage the lifecycles of the instances that are manually added. After the instances are removed from the scaling group, the instances are not released.

Note

You cannot specify this parameter for subscription instances, managed instances, or instances that are stopped in Economical Mode.

Default value: false.

InstanceId.N

String

No

i-28wt4****

The ID of instance N that you want to add to the scaling group. Instance N can be an ECS instance, elastic container instance, managed instance, or instance stopped in Economical Mode. Valid values of N: 1 to 20.

Examples:

  • ID of an ECS instance: i-28wt4****.

  • ID of an elastic container instance: eci-bp17gw49eu09yiwm****.

  • ID of a managed instance: mi-2cx*****.

  • ID of an instance stopped in Economical Mode: i-2cd2f****

Note

You can add only instances of the same type in each call.

LoadBalancerWeight.N

Integer

No

50

The weight of ECS instance N or elastic container instance N as a backend server of the associated Server Load Balancer (SLB) instance. Valid values of N: 1 to 20. Valid values of this parameter: 1 to 100.

Note

You cannot specify this parameter for managed instances or instances that are stopped in Economical Mode.

Default value: 50.

LifecycleHook

Boolean

No

false

Specifies whether to trigger a lifecycle hook when instances are added to the scaling group. Valid values:

  • true

  • false

Note

You cannot specify this parameter for managed instances or instances that are stopped in Economical Mode.

Default value: false.

RegionId

String

No

cn-qingdao

The region ID of the scaling group.

ClientToken

String

No

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

The client token that you want to use 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-bp1crxor24s28xf1****

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=AttachInstances
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&Entrusted=false
&InstanceId=["i-28wt4****"]
&LoadBalancerWeight=[50]
&LifecycleHook=false
&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

<AttachInstancesResponse>
    <ScalingActivityId>asa-bp1crxor24s28xf1****</ScalingActivityId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</AttachInstancesResponse>

JSON format

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

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

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 specified scaling group is not in the Active state.

404

InvalidInstanceId.NotFound

Instance "XXX" does not exist.

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

400

InvalidInstanceId. RegionMismatch

Instance "XXX" and the specified scaling group are not in the same Region.

The specified ECS instance or elastic container instance does not reside in the same region as the specified scaling group.

400

InvalidInstanceId.InstanceTypeMismatch

Instance "XXX" and existing Active scaling configurations have different instance types.

The instance type of the specified ECS instance or elastic container instance is different from the instance type in the active scaling configuration.

400

IncorrectInstanceStatus

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

The specified ECS instance or elastic container instance is not in the Running state.

400

InvalidInstanceId. NetworkTypeMismatch

The network type of instance "XXX" does not support this action.

The network type of the specified ECS instance or elastic container instance is different from the network type of the scaling group.

400

InvalidInstanceId.VPCMismatch

Instance "XXX" and the specified scaling group are not in the same VPC.

The specified ECS instance or elastic container instance that you want to add does not reside in the same VPC as the specified scaling group.

400

InvalidInstanceId.InUse

Instance "XXX" is already attached to another scaling group.

The specified ECS instance or elastic container instance belong to another scaling group.

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 ongoing scaling activities.

400

IncorrectLoadBalancerStatus

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

The SLB instance that is associated with the specified scaling group is not in the Active state.

400

IncorrectLoadBalancerHealthCheck

The current health check type of specified load balancer does not support this action.

The health check feature is disabled for the SLB instance that is associated with the specified scaling group.

400

InvalidLoadBalancerId.IncorrectInstanceNetworkType

The network type of the instance in specified load balancer does not support this action.

The network type of an ECS instance or elastic container instance that is attached to the specified SLB instance is different from the network type of the scaling group.

400

InvalidLoadBalancerId.VPCMismatch

The specified virtual switch and the instance in specified load balancer are not in the same VPC.

An ECS instance or elastic container instance that is attached to the specified SLB instance does not reside in the same VPC as the vSwitch that is specified by VSwitchId.

400

IncorrectDBInstanceStatus

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

The ApsaraDB RDS instance that is associated with the specified scaling group is not in the Running state.

400

QuotaExceeded.DBInstanceSecurityIP

Security IP quota exceeded in DB instance "XXX".

The maximum number of IP addresses in the IP address whitelist of the ApsaraDB RDS instance that is associated with the specified scaling group has been reached.

400

QuotaExceeded.SecurityGroupInstance

Instance quota exceeded in the specified security group.

The maximum number of ECS instances or elastic container instances that can be associated with the specified security group has been reached.

400

IncorrectCapacity.MaxSize

To attach the instances, the total capacity will be greater than the MaxSize.

The total number of ECS instances or elastic container instances specified by Total Capacity exceeds the value of MaxSize.