Manually adds Elastic Compute Service (ECS) 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.

When you add ECS instances to a scaling group, take note of the following limits:

  • The instances must be located in the same region as the scaling group.
  • The instances must be in the Running state.
  • The instances must not be added to other scaling groups.
  • The instances must use the subscription or pay-as-you-go billing method or be preemptible instances.
  • If the VswitchID parameter is specified for a scaling group, ECS instances that are in the classic network or 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, ECS instances of the VPC type 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 without waiting for the cooldown time to expire.

A successful call only means that Auto Scaling accepts the request, and does not mean that the scaling activity can succeed. You can obtain the status of a scaling activity based on the return value of the ScalingActivityId parameter.

If the sum of the number of ECS instances to be added and the number of existing ECS instances in the scaling group is greater than the MaxSize value, the call fails.

ECS 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 ECS instances when you manually add the ECS instances to the scaling group. Valid values:

  • true: The scaling group manages the lifecycle of ECS instances that are manually added in the similar way the scaling group manages the lifecycle of ECS instances that are automatically created. When the instances are removed from the scaling group, the instances are automatically released. However, when the instances are removed from the scaling group by calling the DetachInstances operation, the instances are not released.
  • false: The scaling group does not manage the lifecycle of ECS instances that are manually added. After the instances are removed from the scaling group, the instances are not released.
Note This parameter is not available 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.

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

The ID of ECS instance N to be added. Valid values of N: 1 to 20.

LoadBalancerWeight.N Integer No 50

The weight of ECS instance N as a Server Load Balancer (SLB) backend server. 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

https://ess.aliyuncs.com/?Action=AttachInstances
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&InstanceId.1=i-28wt4****
&<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

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

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 in the current 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 ECS instance does not exist in the current account.

400

InvalidInstanceId. RegionMismatch

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

The error message returned because the specified ECS 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 ECS instance is different from the specified 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 ECS 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 ECS 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 error message returned because the added ECS instance 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 ECS instance has been 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 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 the ECS 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 the ECS instance that is attached to the specified SLB instance is not in the same VPC as the vSwitch specified by VSwitchID.

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 that are added to the 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 error message returned because the maximum number of ECS instances 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 ECS instances as indicated by Total Capacity exceeds the specified value of MaxSize after ECS instances are added to the specified scaling group.