You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Best Practices
Rapidly deploying ECS instances by calling OpenAPI
Copy page
Download PDF
Rapidly deploying ECS instances by calling OpenAPI
This topic describes how to rapidly deploy a large number of ECS instances by calling the OpenAPI, meeting user requirements for highly scalable computing power. For users in social media, online education, and other fields that stage online hot events, this solution can significantly enhance the user experience of their customers.​
Applicable scope​
This applies to application scenarios where a large number of ECS instances need to be delivered quickly in a short period. For example, customers in the interactive entertainment, social media, or online education sectors often need to acquire and use a large number of ECS resources in an extremely short time due to the occurrence of hot events or organized hot activities.​
Software version​
tip​
This solution is provided only for demonstration purposes. You can ​configure your actual environment based on your needs.​
  • Operating system of the local computer: Windows 10​
  • Postman version: v9.31.0​
Practice planning​
This practice enables rapid deployment of a large number of ECS instances by calling the OpenAPI. Before you call the OpenAPI, you need to plan in advance for the following network configurations: VPC CIDR block, subnet CIDR block, security group, network interface, and route table. Additionally, you need to select the type and image of the ECS instance that you want to create. The security group, network interface, and route table are created by default by the system in this practice. The configuration of your actual environment must be determined based on your specific business requirements.​
VPC CIDR block​
You can use one of the following CIDR blocks or a subset of one of them as the CIDR block for the VPC:​
  • 192.168.0.0/16-24 (default)​
  • 10.0.0.0/8-24​
  • 172.16.0.0/12-24​
In this practice, 192.168.0.0/16 is selected as the CIDR block for the VPC.​
Subnet CIDR block​
Subnet CIDR block requirements:​
  • The subnet CIDR block supports a mask length ranging from 16 to 29 bits.​
  • The subnet CIDR block must be contained within the CIDR block of the VPC.​
  • The subnet CIDR block cannot be the same as the destination CIDR block of any route entry in the VPC, but it can be a subset of the destination CIDR block.​
  • The first IP address and the last three IP addresses of each subnet are reserved by the system. For example, if the CIDR block of the subnet is 192.168.0.0/24, then the four IP addresses 192.168.0.0, 192.168.0.253, 192.168.0.254, and 192.168.0.255 are system-reserved IP addresses.​
In this practice, 192.168.0.0/24 is selected as the subnet CIDR block.​
ECS instance type​
  1. Log in to the ECS console. ​
  1. In the left-side navigation pane, select "Instances & Images > Instances".​
  1. Click "Create instance" and configure the parameters described in the following table to obtain all types of ECS instance that you can create.​
  • ​
    Category​
    Description​
    Billing method​
    Pay-as-you-go​
    Region and AZ​
    China (Beijing) A​
    ​
  1. In this practice, General-purpose and ecs.g2i.large are selected as the instance type. After you view the instance type information, click "Cancel" in the lower right corner.​
ECS instance image​
  1. In the left navigation pane, select "Images" to enter the image list page.​
  1. On the image list page, you can view public images, or import custom images based on your needs.​
  1. In this practice, an image running CentOS 7.6 64 bit with the ID image-ebgzajl1peeh8jc6**** is used.​
Use Postman to call the OpenAPI​
In this practice, Postman is used to construct OpenAPI requests. Compared with other methods, Postman features an easy-to-use graphical user interface (GUI), can save the history of API requests, and uses test suites (Collections) to manage and organize API operations more effectively. These features facilitate the synchronization of API data among teams.​
Refer to the official documentation center to configure OpenAPI parameters. For more information, see VPC and ECS. For the API operations involved in this practice, refer to Related documents.​
Install Postman​
Download the installation package​
On the Download Postman page, click "Download the App" and download the corresponding installation package according to the configuration of your computer.​
Install Postman​
  1. Double-click the downloaded installation package. The software will be automatically installed on the local computer.​
  1. Start Postman. If the following page is displayed, Postman is installed.​
  • ​image.png​​
Create a collection​
  1. In Postman, click "Collections > +" to create a collection, and rename it to "Create ECS by OpenAPI".​​​
  1. In the collection, click "... > Add request" and sequentially add the five requests: "CreateVpc", "CreateSubnet", "DescribeSecurityGroups", "RunInstances", and "DescribeInstances".​
  • ​​​
  1. After the requests are added, the following page is displayed.​
  • ​​​
Create an environment variable​
Click "Environments > +" to create an environment variable, and rename it to "veStack OpenAPI" (as an example) to simplify parameter request operations.​
​
​
The parameters​.​
Example value​
Remarks​
URL​
open.volcengineapi.com​
The URL of the OpenAPI.​
AccessKey​
<AccessKey>​
Enter your AccessKey ID. You can perform the following steps to obtain your AccessKey pair.​
1. Log in to the product console.​
2. Move the cursor to the account name in the upper right corner, and click "API accesskey".​
3. On the Key management page, copy AccessKey and SecretKey.​
SecretKey​
<SecretKey>​
Enter your AccessKey secret. You can perform the preceding steps to obtain your AccessKey secret.​
​
Create a request​
tip​
When you create a request, after you configure the corresponding request parameters, you need to manually enter {{URL}} in the request parameter configuration field and save the configuration.​
Create a CreateVpc request​
  1. Select the "CreateVpc" request, configure the request parameters, and invoke the environment variable.​
  • ​
    The parameters​.​
    Example value​
    Action​
    CreateVpc​
    Version​
    2020-04-01​
    X-Expires​
    300​
    CidrBlock​
    192.168.0.0/16​
    VpcName​
    vpc-test​
    Description​
    Create multiple ECS instances in a batch by using OpenAPI​
    ​
  1. Click "Headers" and configure the request headers on the corresponding tab.​
  • ​alt​​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    AccessKey​
    {{AccessKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{AccessKey}}.​
    SecretKey​
    {{SecretKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{SecretKey}}.​
    Region​
    cn-beijing​
    -​
    Service​
    vpc​
    -​
    ​
  1. Click "Pre-request Script". On the corresponding tab, write the script for the signature mechanism based on your actual needs. For the specific script, see Signature mechanism.​
  • ​alt​​
  1. Click "Tests", enter the following commands on the corresponding tab to extract the VpcId from the API response value and set it as an environment variable for use in subsequent requests.​
  • ​
    var json = JSON.parse(responseBody); ​
    let foobar = json.Result.VpcId; ​
    console.log(foobar) ​
    pm.environment.set("vpcid",foobar);​
    ​
  • ​alt​​
Create a CreateSubnet request​
  1. Select the "CreateSubnet" request, configure the request parameters, and invoke the environment variable.​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    Action​
    CreateSubnet​
    -​
    Version​
    2020-04-01​
    -​
    X-Expires​
    300​
    -​
    CidrBlock​
    192.168.0.0/24​
    -​
    VpcId​
    {{vpcid}}​
    The environment variable that you want to invoke. This parameter is fixed to {{vpcid}}.​
    ZoneId​
    cn-beijing-a​
    -​
    SubnetName​
    sub-test​
    -​
    Description​
    Create multiple ECS instances in a batch by using OpenAPI​
    -​
    ​
  1. Click "Headers" and configure the request headers on the corresponding tab.​
  • ​alt​​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    AccessKey​
    {{AccessKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{AccessKey}}.​
    SecretKey​
    {{SecretKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{SecretKey}}.​
    Region​
    cn-beijing​
    -​
    Service​
    vpc​
    -​
    ​
  1. Click "Pre-request Script". On the corresponding tab, write the script for the signature mechanism based on your actual needs. For the specific script, see Signature mechanism.​
  • ​alt​​
  1. Click "Tests", enter the following commands on the corresponding tab to extract the SubnetId from the API response value and set it as an environment variable for use in subsequent requests.​
  • ​
    var json = JSON.parse(responseBody);​
    let foobar = json.Result.SubnetId;​
    console.log(foobar)​
    pm.environment.set("subnetid",foobar);​
    ​
  • ​alt​​
Create a DescribeSecurityGroups request​
  1. Select the "DescribeSecurityGroups" request, configure the request parameters, and invoke the environment variable.​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    Action​
    DescribeSecurityGroups​
    -​
    Version​
    2020-04-01​
    -​
    X-Expires​
    300​
    -​
    VpcId​
    {{vpcid}}​
    The environment variable that you want to invoke. This parameter is fixed to {{vpcid}}.​
    ​
  1. Click "Headers" and configure the request headers on the corresponding tab.​
  • ​alt​​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    AccessKey​
    {{AccessKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{AccessKey}}.​
    SecretKey​
    {{SecretKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{SecretKey}}.​
    Region​
    cn-beijing​
    -​
    Service​
    vpc​
    -​
    ​
  1. Click "Pre-request Script". On the corresponding tab, write the script for the signature mechanism based on your actual needs. For the specific script, see Signature mechanism.​
  • ​alt​​
  1. Click "Tests", enter the following commands on the corresponding tab to extract the SecurityGroupId from the API response value and set it as an environment variable for use in subsequent requests.​
  • ​
    var json = JSON.parse(responseBody);​
    let foobar = json.Result.SecurityGroups[0].SecurityGroupId;​
    console.log(foobar)​
    pm.environment.set("securitygroupid",foobar);​
    ​
  • ​alt​​
Create a RunInstances request​
  1. Select the "RunInstances" request, configure the request parameters, and invoke the environment variable.​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    Action​
    RunInstances​
    -​
    Version​
    2020-04-01​
    -​
    X-Expires​
    300​
    -​
    ZoneId​
    cn-beijing-a​
    -​
    ImageId​
    image-ebgzajl1peeh8jc6****​
    CentOS 7.6 64 bit​
    InstanceType​
    ecs.g2i.large​
    General-purpose g2i (2 vCPU/8 GiB)​
    InstanceName​
    instance-test​
    -​
    Count​
    10​
    The number of ECS instances that you want to create.​
    Password​
    password@123​
    -​
    KeyPairName​
    keypair​
    • Windows instances do not support the KeyPairName parameter.​
    • If the KeyPairName and Password parameters are configured at the same time, only the KeyPairName parameter takes effect.​
    Volumes.1.VolumeType​
    ESSD​
    -​
    Volumes.1.Size​
    40​
    -​
    Volumes.2.VolumeType​
    ESSD​
    -​
    Volumes.2.Size​
    40​
    -​
    NetworkInterfaces.1.SubnetId​
    {{subnetid}}​
    The environment variable that you want to invoke. This parameter is fixed to {{subnetid}}.​
    NetworkInterfaces.1.SecurityGroupIds.1​
    {{securitygroupid}}​
    The environment variable that you want to invoke. This parameter is fixed to {{securitygroupid}}.​
    InstanceChargeType​
    PostPaid​
    -​
    UniqueSuffix​
    true​
    -​
    SuffixIndex​
    1​
    -​
    SecurityEnhancementStrategy​
    Active​
    ​
    HpcClusterId​
    hpcCluster-1​
    When you create an HPC-optimized instance, specify the ID of the HPC cluster. In this practice, the HPC cluster ID is not selected.​
    ​
  1. Click "Headers" and configure the request headers on the corresponding tab.​
  • ​alt​​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    AccessKey​
    {{AccessKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{AccessKey}}.​
    SecretKey​
    {{SecretKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{SecretKey}}.​
    Region​
    cn-beijing​
    -​
    Service​
    ecs​
    -​
    ​
  1. Click "Pre-request Script". On the corresponding tab, write the script for the signature mechanism based on your actual needs. For the specific script, see Signature mechanism.​
  • ​alt​​
Create a DescribeInstances request​
  1. Select the "DescribeInstances" request, configure the request parameters, and invoke the environment variable.​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    Action​
    DescribeInstances​
    -​
    Version​
    2020-04-01​
    -​
    X-Expires​
    300​
    -​
    ZoneId​
    cn-beijing-a​
    -​
    VpcId​
    {{vpcid}}​
    The environment variable that you want to invoke. This parameter is fixed to {{vpcid}}.​
    ​
  1. Click "Headers" and configure the request headers on the corresponding tab.​
  • ​alt​​
  • ​
    The parameters​.​
    Example value​
    Remarks​
    AccessKey​
    {{AccessKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{AccessKey}}.​
    SecretKey​
    {{SecretKey}}​
    The environment variable that you want to invoke. This parameter is fixed to {{SecretKey}}.​
    Region​
    cn-beijing​
    -​
    Service​
    ecs​
    -​
    ​
  1. Click "Pre-request Script". On the corresponding tab, write the script for the signature mechanism based on your actual needs. For the specific script, see Signature mechanism.​
  • ​alt​​
Run the collection​
  1. Run the collection according to the procedure in the following figure.​
  • ​alt​​
  1. The running result shows that 10 ECS instances are created.​
  • ​alt​​
  1. After you run the collection for the first time, environment variables are automatically populated with the {{vpcid}}, {{subnetid}}, and {{securitygroupid}} for this practice. If you need to batch-create ECS instances again under the same VPC and subnet, you only need to perform two steps: RunInstances and DescribeInstances.​
Verification in the console​
Go to the ECS instances page. In the top menu bar, select the region to which the created instances belong. You can see that 10 ECS instances are running, which indicates that the ECS instances are created.​
Related documents​
Last updated: 2025.11.03 16:31:18