When you use the ALIYUN::ECS::InstanceGroup resource type to batch-create ECS instances, you can give each instance a unique, predictable name and hostname without writing a separate template block per instance.
Set the InstanceName and HostName properties using the following pattern:
name_prefix[begin_number,bits]name_suffix
Naming pattern fields
name_prefix— Required. The fixed prefix that appears at the start of every generated name.-
[begin_number,bits]— The auto-incrementing part.begin_numbersets the starting number;bitssets how many digits the number occupies (zero-padded).The field must meet these requirements:
No spaces inside the brackets.
bitsmust be in the range of 1 to 4.begin_numbermust be in the range of 0 to 9999.
Default behavior for
bits:If you specify only
begin_number(for example,[5]):bitsdefaults to 4, producing a 4-digit zero-padded number.If you write
[]or[,](omitting both values):begin_numberdefaults to 0 andbitsdefaults to 4.If
begin_numberhas more digits thanbitsspecifies (for example,[1234,1]):bitsis overridden and defaults to 4, becausebegin_number(1234) already has four digits. This override applies only whenbegin_numberis in the range of 0 to 9999.
name_suffix— Optional. A fixed string appended after the incrementing number.
Batch instance naming example
The following template creates two ECS instances with distinct names and hostnames.
ROSTemplateFormatVersion: '2015-09-01'
Resources:
WebServer:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ImageId: Cen****
InstanceType: ecs.n4.large
Password: Test1234
MinAmount: 2
MaxAmount: 2
SecurityGroupId: sg-2zedcm7ep5quses0****
SystemDiskCategory: cloud_efficiency
IoOptimized: optimized
InstanceName: my.test-[1114]
HostName: host[]
ROS generates the following names:
Instance names:
my.test-1114andmy.test-1115—InstanceName: my.test-[1114]meansbegin_number=1114,bitsdefaults to 4.Hostnames:
host0000andhost0001—HostName: host[]meansbegin_numberdefaults to 0,bitsdefaults to 4.
Template validation fails if the generated names do not conform to the naming rules for InstanceName and HostName. Verify your pattern produces valid names before deploying the template.