All Products
Document Center

How do I specify different instance names and host names when creating ECS instances in batch?

Last Updated: Apr 12, 2018

ROS resource type ALIYUN::ECS::InstanceGroup can be used to create ECS instances in batch.

When creating ECS instances, you can use the InstanceName and HostName attributes to specify instance names and host names. You can set different instance names and host names for ECS instances as the following pattern: name_prefix[begin_number,bits]name_suffix.

As shown in the preceding pattern, an instance or host name is composed of three parts:

  • name_prefix (required): Specifies the prefix of the instance or host name.

  • [begin_number,bits] (required): Specifies the differences for instance or host names. begin_number specifies the number to start from when you create instance and host names, and bits indicates the number of digits in each number.

    This field can be accurately parsed only when it meets the following conditions:

    • No spaces are in the field.

    • The bits value range is [1, 4].

    • The begin_number value range is [0, 9999].

    • If you only specify the begin_number, the bits value is set to 4 by default.

    • If you specify [begin_number,bits] as [] or [,], the begin_number starts from 0 and the bits value is set to 4 by default.

    • If the specified begin_number has more digits than the bits value, such as [1234,1], the begin_number “1234” is within the range [0, 9999], therefore, the bits value is changed to 4.
  • name_suffix (optional): Specifies the suffix of the instance or host names.

For example:

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Resources" : {
  4. "WebServer": {
  5. "Type": "ALIYUN::ECS::InstanceGroup",
  6. "Properties": {
  7. "ImageId" : "CentOs*",
  8. "InstanceType": "ecs.n4.large",
  9. "Password": "Test1234",
  10. "MinAmount": 2,
  11. "MaxAmount": 2,
  12. "SecurityGroupId": "sg-2zedcm7ep5quses05fs4",
  13. "SystemDiskCategory": "cloud_efficiency",
  14. "IoOptimized": "optimized",
  15. "InstanceName": "my.test-[1114]",
  16. "HostName": "host[]"
  17. }
  18. }
  19. }
  20. }

According to the preceding template, ROS creates two ECS instances.

  • The names of the ECS instance are my.test-1114 and my.test-1115.

  • The two ECS host names are host0000 and host0001.


Even if you use the preceding method to specify instance and host names, the name finally parsed must comply with the InstanceName and HostName definition rules. Otherwise, the instances may fail the pre-creation verification.