Method to provide incremental name to ec2 instances created using auto scaling group in aws

瘦欲@ 提交于 2019-12-13 03:43:51

问题


I am configuring an auto scaling group in aws to create ec2 servers. I want to add incremental value to the name tag when a new instance is created by the auto scaling group (Example server-01, server-02 etc.)

Is there any method to add name tag to resource created using auto scaling group as mentioned above.


回答1:


You could do this with a Lambda, responding to a life-cycle event. The Lambda would call DescribeAutoScalingGroups to find the instance(s) belonging to the ASG, and update those that don't have the tag.

If you simply want to have all of your instances numbered 1..N, then I would recommend listening to shutdown events as well as startup events, and retagging all instances based on their starting timestamp.

If you want to apply sequential numbers to every new instance, you'll need to store the current value somewhere, such as DynamoDB. You'll also need to beware of concurrent executions, and make sure that you use each sequence number once and only once. You can do this by storing an association between sequence number and instance ID.

But why would you want to do this?



来源:https://stackoverflow.com/questions/53615049/method-to-provide-incremental-name-to-ec2-instances-created-using-auto-scaling-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!