All Products
Search
Document Center

Elastic Compute Service:Batch configure sequential names or hostnames for multiple instances

Last Updated:Jan 23, 2024

When you batch create multiple Elastic Compute Service (ECS) instances, the same default instance name or hostname is generated for all instances. To classify the instances or facilitate instance management and identification, you can batch configure sequential instance names or hostnames by specifying a sequence or by using the automatic sorting feature during instance creation.

Specify a sequence to batch configure sequential instance names or hostnames

When you batch create multiple ECS instances, you can specify a sequence to configure sequential names or hostnames for the instances.

Specify a sequence

To specify a sequence for the names and hostnames of multiple ECS instances, configure the instance name parameter and hostname parameter in a fixed format. The format includes fields that specify sequential numeric values.

The system generates names and hostnames that contain the specified numerical sequence for the ECS instances based on the parameters. Specify a sequence by configuring the instance name parameter or hostname parameter in the following format: name_prefix[begin_number,bits]name_suffix. The following tables describe the fields that are contained in the format and provide examples on how to configure the parameters.

Fields in the format

Field

Description

Example

name_prefix

The prefix of the instance names or hostnames.

Note

You must specify a prefix when you configure sequential names. Otherwise, the names are regarded as common names.

k8s-node-

[begin_number,bits]

The sequential numeric values that you want to add to the instance names or hostnames. The instance names or hostnames increment based on the settings of this field.

  • begin_number: the start value of the sequential numeric values. Valid values: 0 to 999999. Default value: 0.

  • bits: the number of digits in the sequential numeric value. Valid values: 1 to 6. Default value: 6.

Important
  • The [begin_number,bits] field cannot contain spaces.

  • If the number of digits in the value of begin_number is greater than the value of bits, the default value 6 is used for bits.

  • Up to 999,999 ECS instances can share the same prefix and suffix. Excess instances use 999999 as the sequential numeric value of their instance names and hostnames.

  • If you set [begin_number,bits] to [] or [,], the begin_number values start from 0 and bits is set to the default value 6.

  • If you specify a value only for begin_number in the [begin_number,bits] field, for example, 99 or [99,], bits is set to the default value 6.

[0,6]

name_suffix

The suffix of the instance names or hostnames.

-ecshost

Parameter examples

Example

Generated name (if three ECS instances are created at the same time)

k8s-node-[]-ecshost or k8s-node-[,]-ecshost

  • k8s-node-000000-ecshost

  • k8s-node-000001-ecshost

  • k8s-node-000002-ecshost

k8s-node-[99]-ecshost or k8s-node-[99,]-ecshost

  • k8s-node-000099-ecshost

  • k8s-node-000100-ecshost

  • k8s-node-000101-ecshost

k8s-node-[99,1]-ecshost

  • k8s-node-000099-ecshost

  • k8s-node-000100-ecshost

  • k8s-node-000101-ecshost

k8s-node-[999998]-ecshost

  • k8s-node-999998-ecshost

  • k8s-node-999999-ecshost

  • k8s-node-999999-ecshost

k8s-node-[0,4]

  • k8s-node-0000

  • k8s-node-0001

  • k8s-node-0002

Procedure

In the examples, three ECS instances are created, the instance names and hostnames start with k8s-node- and increment from 0006, and the hostnames end with -ecshost.

Important

The instance name or hostname that you specify must meet the following requirements:

  • Instance name: The name must be 2 to 128 characters in length and must start with a letter. It can contain letters, digits, periods (.), underscores (_), colons (:), and hyphens (-).

  • Hostname:

    • For Windows, the hostname must be 2 to 15 characters in length and can contain letters, digits, and hyphens (-). The hostname cannot start or end with a hyphen (-), contain consecutive hyphens (-), or contain only digits.

    • For other operating systems such as Linux, the hostname must be 2 to 64 characters in length. You can use periods (.) to separate the hostname into multiple segments. Each segment can contain letters, digits, and hyphens (-) and cannot contain consecutive periods (.) or hyphens (-). The hostname cannot start or end with a period (.) or a hyphen (-).

Use the ECS console

For information about how to create an ECS instance, see Create an instance on the Custom Launch tab. When you create ECS instances in the ECS console, complete the following configurations:

  • Quantity: On the right side of the Custom Launch tab, click the plus sign to increase the value in the Quantity spin box to 3.购买实例数量.png

  • Batch configure sequential instance names or hostnames in the following format: name_prefix[begin_number,bits]name_suffix. For information about how to configure the fields that are contained in the format, see the Specify a sequence section in this topic.

    Important

    The example is used only to show how to specify a sequence. Sequential Suffix is not selected.

    • Instance Name: Enter an instance name. For example, to create three ECS instances whose names start with k8s-node- and increment from 0006, enter k8s-node-[6,4] in the Instance Name field.

    • Hostname: Select Custom Sequential Hostname below the Hostname field and enter a hostname. For example, to create three ECS instances whose hostnames start with k8s-node-, increment from 0006, and end with -ecshost, enter k8s-node-[6,4]-ecshost in the Hostname field.

    指定排序.png

After you complete the configurations and click Create Order, a success message appears. You can click Console in the message to view instance information.

  • You can view the new ECS instances on the Instances page. In this example, the generated instance names are k8s-node-0006, k8s-node-0007, and k8s-node-0008.查看批量创建的ECS实例.png

  • You can go to the Instance Details page of each new ECS instance and view the hostname of the instance in the Other Information section. In this example, the hostnames that are generated for the new ECS instances are k8s-node-0006-ecshost, k8s-node-0007-ecshost, and k8s-node-0008-ecshost.

Call an API operation

You can call the RunInstances operation to create ECS instances and specify names and hostnames for the instances. Configure the following parameters to specify sequential instance names and hostnames when you call the RunInstances operation:

Specify values for the InstanceName and HostName parameters in the following format: name_prefix[begin_number,bits]name_suffix. For information about how to configure the fields that are contained in the format, see the Specify a sequence section in this topic.

In this example, three ECS instances are created, the instance names and hostnames start with k8s-node- and increment from 0006, and the hostnames end with -ecshost. Configure the following parameters:

  • Amount: 3

  • InstanceName: k8s-node-[6,4]

  • HostName: k8s-node-[6,4]-ecshost

Important

This example is used only to show how to specify a sequence. The UniqueSuffix parameter is set to false.

In this example, the generated instance names are k8s-node-0006, k8s-node-0007, and k8s-node-0008, and the generated hostnames are k8s-node-0006-ecshost, k8s-node-0007-ecshost, and k8s-node-0008-ecshost.

Use the automatic sorting feature to batch configure sequential instance names or hostnames

When you batch create multiple ECS instances, you can enable the automatic sorting feature to automatically add sequential suffixes to the instance names and hostnames.

Use the automatic sorting feature

You can use the automatic sorting feature to automatically add three-digit sequential suffixes to instance names and hostnames. The sequential suffixes range from 001 to 999. After you enable the automatic sorting feature, the added suffix starts from 001 and increments for each ECS instance. When ECS instances are created, instance names and hostnames that have different suffixes are generated.

By default, the automatic sorting feature is disabled. When you create ECS instances, enable the automatic sorting feature and enter an instance name and a hostname. The system adds sequential suffixes to the instance name and hostname that you specify to generate new instances names and hostnames.

The following table describes the format in which you can enter an instance name or a hostname when you enable the automatic sorting feature.

Important

If you want to use a specific sequence together with the automatic sorting feature, specify the name_suffix field. If you do not specify the field, the automatic sorting feature does not take effect. For information about how to specify a sequence, see the Specify a sequence section in this topic.

Name formats

Format (instance name or hostname)

Example

Generated name (if three ECS instances are created at the same time)

Common names

ecs

  • ecs001

  • ecs002

  • ecs003

Sequential names that contain a specific sequence: name_prefix[begin_number,bits]name_suffix

k8s-node-[]-ecshost or k8s-node-[,]-ecshost

  • k8s-node-000000-ecshost001

  • k8s-node-000001-ecshost002

  • k8s-node-000002-ecshost003

Note

The specified sequence and the automatic sorting feature take effect at the same time.

Sequential names that contain a specific sequence: name_prefix[begin_number,bits]

k8s-node-[0,4]

  • k8s-node-0000

  • k8s-node-0001

  • k8s-node-0002

Note

The name_suffix field is not specified, and automatic sorting does not take effect.

Procedure

In the examples, three ECS instances are created, ecs is specified as the instance name, ecshost is specified as the hostname, and a sequential suffix is automatically added to the specified instance name and hostname to generate a new name and hostname for each instance.

Important

The instance name or hostname that you specify must meet the following requirements:

  • Instance name: The name must be 2 to 128 characters in length and must start with a letter. It can contain letters, digits, periods (.), underscores (_), colons (:), and hyphens (-).

  • Hostname:

    • For Windows, the hostname must be 2 to 15 characters in length and can contain letters, digits, and hyphens (-). The hostname cannot start or end with a hyphen (-), contain consecutive hyphens (-), or contain only digits.

    • For other operating systems such as Linux, the hostname must be 2 to 64 characters in length. You can use periods (.) to separate the hostname into multiple segments. Each segment can contain letters, digits, and hyphens (-) and cannot contain consecutive periods (.) or hyphens (-). The hostname cannot start or end with a period (.) or a hyphen (-).

Use the ECS console

For information about how to create an ECS instance, see Create an instance on the Custom Launch tab. When you create ECS instances in the ECS console, complete the following configurations:

  • Quantity: On the right side of the Custom Launch tab, click the plus sign to increase the value in the Quantity spin box to 3.购买实例数量.png

  • Configure sequential instance names or hostnames that you want to automatically generate. For information about the rules for automatic sorting, see the Use the automatic sorting feature section in this topic.

    • Instance Name: Enter an instance name. For example, to create three ECS instances whose names start with ecs, enter ecs in the Instance Name field.

    • Hostname: Enter a hostname. For example, to create three ECS instances whose hostnames start with ecshost, enter ecshost in the Hostname field.

    • Sequential Suffix: If you select this parameter, the system adds sequential suffixes to the values of the Instance Name and Hostname parameters and sorts the values.

    自动排序.png

After you complete the configurations and click Create Order, a success message appears. You can click Console in the message to view instance information.

  • You can view the new ECS instances on the Instances page. In this example, the generated instance names are ecs001, ecs002, and ecs003.

  • You can go to the Instance Details page of each new ECS instance and view the hostname of the instance in the Other Information section. In this example, the generated hostnames are ecshost001, ecshost002, and ecshost003.

Call an API operation

You can call the RunInstances operation to create ECS instances and configure sequential instance names and hostnames that you want to automatically generate for the instances. Configure the following parameters when you call the RunInstances operation:

Set UniqueSuffix to true. The system adds sequential suffixes to the values of the InstanceName and HostName parameters and sorts the values. The added suffix starts from 001 and increments for each ECS instance. For information about the rules for automatic sorting, see the Use the automatic sorting feature section in this topic.

In this example, sequential names and hostnames are automatically generated for three ECS instances. Configure the following parameters:

  • Amount: 3

  • InstanceName: ecs

  • HostName: ecshost

  • UniqueSuffix: true

In this example, the generated instance names are ecs001, ecs002, and ecs003, and the generated hostnames are ecshost001, ecshost002, and ecshost003.

References