This topic describes how to create a scaling configuration for a scaling group, and how to specify an ECS instance template for automatic scaling.

Prerequisites

  • After a scaling group is created, the specified VPC cannot be modified. You must specify a security group when creating a scaling configuration. Make sure that the security group and the scaling group are in the same VPC. If no security group exists in the VPC where the scaling group is located, you must create a security group. For more information, see Create a security group.
  • To use the API sample code provided in this topic, you must configure API access permissions. For more information, see Create an AccessKey.

Background information

The process of creating a scaling configuration is similar to that of creating an ECS instance. However, the scaling configuration of a scaling group is the template for ECS instances to be created during scale-out operations. A scaling configuration has special features such as supporting different instance types, but does not support configuring certain parameters, such as region and VPCs. You can refer to the actual interface of the Auto Scaling console when using this document. You can view a brief description of each parameter in the console. For more information about parameter descriptions, see Create an instance by using the provided wizard.

Procedure in the Auto Scaling console

  1. Log on to the Auto Scaling console.
  2. In the top navigation bar, select a region.
  3. Find the target scaling group and use one of the following methods to open the details page of the scaling group:
    • Click the ID of the scaling group in the Scaling Group Name/ID column.
    • Click Manage in the Actions column.
  4. In the left-side navigation pane, click Instance Configuration Source. On the Scaling Configurations page that appears, click Create Scaling Configuration.
  5. On the Basic Configurations page that appears, configure Billing Method, Instance Type, Image, Storage, Network Billing Method, and Security Group. Click Next: System Configurations.
    Note In the basic configurations:
    • Billing method: only Pay-As-You-Go and Preemptible Instance are supported.
    • Instance: Multiple instance types are supported. When the inventory of a specific instance type is insufficient, alternate instance types will be used to improve the scaling success rate.
  6. On the System Configurations page, configure Tags (optional), Resource Groups (optional), Logon Credentials, Instance Name (optional), and advanced options (optional). Click Next: Preview.
    Note Advanced options are available only for scaling configurations in a VPC-type scaling group. The options include RAM Role and User Data.
  7. On the Preview page, check your configurations, enter the scaling configuration name, and click Create.
  8. In the Created dialog box that appears, click Enable Configuration.

API sample code

A scaling configuration is a template used by a scaling group to create ECS instances. Before you call an API operation to create a scaling configuration, make sure that the request contains the ID of a scaling group, the ID of a security group to which ECS instances will belong, the ID of an ECS instance image, and the types of ECS instances to be used.

We recommend that you choose an Alibaba Cloud SDK based on the programming language of your choice. The following sample code uses the Java SDK as an example:
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>4.0.3</version>
</dependency>
*/
public class CommonRpc {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("ess.aliyuncs.com");
        request.setVersion("2014-08-28");
        request.setAction("CreateScalingConfiguration");
        request.putQueryParameter("ScalingGroupId", "asg-bp1a4xzjr1ypd601****");
        request.putQueryParameter("SecurityGroupId", "sg-bp147qpndp7iyj08****");
        request.putQueryParameter("ImageId", "centos6u5_64_20G_aliaeg****.vhd");
        request.putQueryParameter("InstanceType", "ecs.t1.xsmall");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
After you have initiated a call through the Java SDK or other methods, the request body is similar to the following content:
https://ess.aliyuncs.com/?Action=CreateScalingConfiguration
&ImageId=centos6u5_64_20G_aliaeg****.vhd
&InstanceType=ecs.t1.xsmall
&ScalingGroupId=asg-bp1a4xzjr1ypd601****
&SecurityGroupId=sg-bp147qpndp7iyj08****
&Version=2014-08-28
In the request,
  • centos6u5_64_20G_aliaeg****.vhd indicates the ID of the ECS instance image.
  • ecs.t1.xsmall indicates the type of the ECS instances.
  • AG6CQdPU8OKdwLjgZc**** indicates the ID of the scaling group.
  • sg-280**** indicates the ID of the scaling group to which the ECS instances will belong.
  • 2014-08-28 indicates the version of the API.

You can also customize attributes such as different instance types and ECS instance disks. For more information about the API, see CreateScalingConfiguration.