Amazon-Web-Services – Automatic Extension Group Host Name and Cloud-Init

From a short search-it seems that there is no way to set dynamic hostnames for members of the auto-scaling group. OpenStack Heat uses the indexing function-but I can’t find anything related to the AWS auto-scaling group Content.

For example, using OpenStack Heat-automatically assign host names to nodes based on the number of nodes in the auto-scaling group:

instance_group:< br /> type: OS::Heat::ResourceGroup
properties:
count: {get_param: instance_number }
resource_def:
type: OS::Nova::Server
properties:
name: instance%index%

If I have 3 instances in the auto-scaling group, it will give me the following

< pre>instance0
instance1
instance2

Is there a similar method that can be used with AWS auto-scaling group startup configuration and/or cloud-init?

If you insist on some unreasonable conventions, I found a very good solution. < p>

Each type of EC2 instance I start, whether it is in the auto-scaling group, whether there is such an N server, or its independent instance, I will create an instance configuration file for it. In any case, In my experience, this is a good idea, even if you don’t need an instance to access any aws service, it doesn’t hurt to have a role/profile with empty permissions, which makes it easier to access. If you need it, you can use s3 bucket or Anything else.

Then when the server of the user_data script (or your configuration management tool, if you use something like puppet or ansible) starts, I query the instance configuration file name from the metadata service, and Attach something unique to each server, such as a private IP, and set it as the hostname.

You will end up with a hostname like webserver-10-0-12-58, which is useful for Each server is human-readable and unique.

(The disadvantage of this incremental integer is that these are unpredictable and cannot be used to set unique behaviors for a single server. For example, if you If you have webserver-{0-8} and need to run a certain process on a server, you can use logic such as hostname == webserver-0 and then run_thing.)

< p>From a short search-it seems that there is no way to set dynamic hostnames for members of the auto-scaling group. OpenStack Heat uses the index presence function-but I can’t find anything related to the AWS auto-scaling group.

For example, using OpenStack Heat-automatically assign host names to nodes based on the number of nodes in the auto-scaling group:

instance_group:
type: OS::Heat ::ResourceGroup
properties:
count: {get_param: instance_number }
resource_def:
type: OS::Nova::Server
properties:
name : inst ance%index%

If I have 3 instances in the auto-scaling group, it will give me the following content

instance0
instance1
instance2

Is there a similar method that can be used with AWS auto-scaling group startup configuration and/or cloud-init?

If you insist on some unreasonable conventions, I found a very good solution.

I started For each EC2 instance, whether it is in the auto-scaling group or not, or its independent instance, I will create an instance profile for it. Anyway, in my experience, this is a good idea, even You don’t need an instance to access any aws service, and it doesn’t hurt to have a role/configuration file with empty permissions, which makes it easier to access. If you need it, you can use an s3 bucket or anything else.

Then When the server of the user_data script (or your configuration management tool, if you use something like puppet or ansible) starts, I query the instance configuration file name from the metadata service and attach some unique things to each server, such as private IP, and set it as the hostname.

You will end up with a hostname like webserver-10-0-12-58, which is human-readable for every server and Is unique.

(The disadvantage of this incremental integer is that these are unpredictable and cannot be used to set unique behavior for a single server. For example, if you have a webserver-{0-8} and need to run a For each process on a server, you can use logic such as hostname == webserver-0 and then run_thing.)

Leave a Comment

Your email address will not be published.