All Products
Search
Document Center

Auto Scaling:AttachInstances

Last Updated:Jan 21, 2025

Adds instances to a scaling group. You can call the AttachInstances operation to add Elastic Compute Service (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 does not have scaling activities in progress.

  • If you want to add ECS instances or elastic container instances to the scaling group, take note of the following items:

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

    • The instances must be in the Running state.

    • The instances must not be part of another scaling group.

    • The instance must be billed on a subscription or pay-as-you-go basis, or the instance must be a preemptible instance.

    • 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, take note of the following items:

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

    • The managed instances must not be part of 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 use this operation, take note of the following items:

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

    • A successful call indicates that Auto Scaling has accepted the request, but does not guarantee that the scaling activity will be successful. 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 not exceed the maximum allowed after you call the operation. Otherwise, the operation will fail.

    • 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 the scaling group can manage the lifecycles of instances that are manually added. Valid values:

  • true: The scaling group manages the lifecycles of manually added instances in the same way it manages those that are automatically created. In this case, Auto Scaling releases the instances when they are removed from the scaling group. This rule does not apply to instances that are removed by calling the DetachInstances operation.

  • false: The scaling group cannot manage the lifecycles of instances that are manually added. When removed from the scaling group, these 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.

Sample instance IDs:

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

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

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

  • Sample 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 load balancing weight of ECS instance N or elastic container instance N. 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 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 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 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.

IgnoreInvalidInstance

Boolean

No

false

Specifies whether to ignore invalid instances when you add a batch of instances to the scaling group. Valid values:

  • true: ignores invalid instances. If invalid instances exist and valid instances are added, the corresponding scaling activity enters the Warning state. You can check the scaling activity details to view the invalid instances that are ignored.

  • false: does not ignore invalid instances. If invalid instances exist in the batch of instances that you want to add to the scaling group, an error is reported.

Default value: false.

Response parameters

Parameter

Type

Example

Description

ScalingActivityId

String

asa-bp1crxor24s28xf1****

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=AttachInstances
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&Entrusted=false
&InstanceId=["i-28wt4****"]
&LoadBalancerWeight=[50]
&LifecycleHook=false
&RegionId=cn-qingdao
&ClientToken=123e4567-e89b-12d3-a456-42665544****
&IgnoreInvalidInstance=false
&<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 load balancer 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 load balancer 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 load balancer 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 load balancer 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 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.