Manually adds Elastic Compute Service (ECS) instances or elastic container instances to a scaling group.

Description

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

  • The scaling group is in the Active state.
  • No scaling activities in the scaling group are in progress.

The ECS instances and the elastic container instances that you want to add to a scaling group must meet the following requirements:

  • The instances reside in the same region as the scaling group.
  • The instances are in the Running state.
  • The instances are not added to other scaling groups.
  • The instances use the subscription or pay-as-you-go billing method, or are preemptible instances.
  • If the VswitchID parameter is specified for a 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 the VswitchID parameter is not specified for a scaling group, the instances that are in VPCs cannot be added to the scaling group.

If no scaling activities in the specified scaling group are in progress, the operation can trigger scaling activities even before the cooldown time expires.

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 by using the value of the ScalingActivityId parameter in the response.

If the sum of the number of instances that you want to add and the number of existing instances in the scaling group is greater than the MaxSize value, the call fails.

Instances that are manually added by calling the AttachInstances 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 manages the lifecycle of instances that are manually added to the scaling group. Valid values:

  • true: The scaling group manages the lifecycle of instances that are manually added in a similar manner in which the scaling group manages the lifecycle of automatically created instances. When the instances are removed from the scaling group, the instances are automatically released. However, if you call the DetachInstances operation to remove the instances from the scaling group, the instances are not released.
  • false: The scaling group does not manage the lifecycle of instances that are manually added. After the instances are removed from the scaling group, the instances are not released.
Note This parameter is unavailable for subscription instances.

Default value: false.

LifecycleHook Boolean No false

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

  • true
  • false

Default value: false.

RegionId String No cn-qingdao

The ID of the region where the scaling group resides.

InstanceId.N String No i-28wt4****

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

Examples:

  • The ID of the ECS instance that you want to add is i-28wt4****.
  • The ID of the elastic container instance that you want to add is eci-bp17gw49eu09yiwm****.
LoadBalancerWeight.N Integer No 50

The weight of instance N as a backend server of the Server Load Balancer (SLB) instance that is associated with the scaling group to which you want to add instance N. Valid values of N: 1 to 20. Valid values of this parameter: 1 to 100.

Default value: 50.

Response parameters

Parameter Type Example Description
ScalingActivityId String asa-bp1crxor24s28xf1****

The ID of the scaling activity.

RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

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
&<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-A3DC0DE3C83E</RequestId>
</AttachInstancesResponse>

JSON format

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

{
  "ScalingActivityId" : "asa-bp1crxor24s28xf1****",
  "RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

For a list of error codes, visit the API Error Center.

HTTP status code

Error code

Error message

Description

404

InvalidScalingGroupId.NotFound

The specified scaling group does not exist.

The error message returned because 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.

The error message returned because Auto Scaling is not authorized to call the specified operation.

400

IncorrectScalingGroupStatus

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

The error message returned because the specified scaling group is not in the Active state.

404

InvalidInstanceId.NotFound

Instance "XXX" does not exist.

The error message returned because the specified 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 error message returned because the specified instance and the scaling group are not in the same region.

400

InvalidInstanceId.InstanceTypeMismatch

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

The error message returned because the instance type of the specified 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 error message returned because the specified instance is not in the Running state.

400

InvalidInstanceId. NetworkTypeMismatch

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

The error message returned because the network type of the specified instance is different from that of the scaling group.

400

InvalidInstanceId.VPCMismatch

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

The error message returned because the instance that you want to add and the specified scaling group are not in the same VPC.

400

InvalidInstanceId.InUse

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

The error message returned because the specified instance is already added 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 error message returned because scaling activities are in progress in the specified scaling group.

400

IncorrectLoadBalancerStatus

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

The error message returned because the specified SLB instance that is associated with the 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 error message returned because 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 error message returned because the network type of an 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.

The error message returned because an instance that is attached to the specified SLB instance is not in the same VPC as the vSwitch that is specified by the VSwitchID parameter.

400

IncorrectDBInstanceStatus

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

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

400

QuotaExceeded.DBInstanceSecurityIP

Security IP quota exceeded in DB instance "XXX".

The error message returned because the maximum number of IP addresses in the whitelist that manages access to 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 error message returned because the maximum number of instances that are 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 error message returned because the total number of instances as indicated by Total Capacity exceeds the specified value of MaxSize after you add instances to the specified scaling group.