Is there a logical way to have sequentially numbered hostnames with servers that are autoscaling but not sequentially killed?
So if server13 is killed and server14/15 are alive, and the cluster upscales with 2 servers it will add a server with hostnames server13 and server16?
Best Answer
If
hostname
refers to only the output of thehostname
command (on the instance itself), assign a instance profile that allows for the instance to query existing autoscaling group members and their tags using AWS CLI. Then use a tag to denote the server hostname or index, and upon autoscaling adding a new instance, have it look at the current list of servers and assign a missing hostname to it. You can useUserData
to fire up this script.If
hostname
refers to an actual DNS name (in Route 53): you could maybe utilize an autoscaling lifecycle hook and have it fire a lambda that does the appropriate Route 53 record set changes (similar logic as above).