Suppose I spin up a machine in EC2. Every time I stop/start the machine the following things change (reboots are safe--they don't cause these to change):
- public IP address
- public DNS record
- private IP address
- private DNS record
- removes associated elastic IP
How can I reliably connect to the machine if the addresses/DNS records change every time it is started?
Should I stick with EIPs but add a startup script to reassociate it with my instance when it boots?
There's got to be a better way!
If you stop an instance in EC2, then any associated Elastic IPs are disassociated, and you must reassociate them yourself. However, the same doesn't apply to instances in VPC; in this case the Elastic IP remains associated, even when the instance is stopped.
See the Elastic IP Address documentation for further details.
Another possibility is to use a dynamic DNS service like dyndns.org. You install a client on the server which periodically checks it's IP agains a DNS record. If it's different it pushes out an update.