问题
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