If hostname
refers to only the output of the hostname
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 use UserData
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).