If you give your EC2 instance a "hostname" tag then this will be added as an alias for that host.
https://gist.github.com/bootrino/7ae38d38dabf0a4be1093742471...
This article gives an overview for how to configure AWS to run a Lambda function like this, triggered any time there is a state change in your EC2 instances.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/L...
Output looks like this:
ubuntu@ip-10-0-0-229:~$ --> curl https://s3.eu-west-1.amazonaws.com/bucketname/hosts
10.0.0.196 ip-10-0-0-196.eu-west-1.compute.internal
10.0.0.229 ip-10-0-0-229.eu-west-1.compute.internal somecustomhostname.foo.com
10.0.0.138 ip-10-0-0-138.eu-west-1.compute.internal
10.0.1.53 ip-10-0-1-53.eu-west-1.compute.internal
10.0.0.4 ip-10-0-0-4.eu-west-1.compute.internal
ubuntu@ip-10-0-0-229:~$ -->