I have a simple question, with hopefully a simple solution.
I have a private Route53 zone, which is only available within a VPC. I want some kind of dynamic dns, so when servers are launched, they register themselves with the Route53 zone.
However, I can't come up with a clean solution. The hostname and domain are already set correctly by cloud-init and user-data, but I want a solution that accomplishes the following:
Register the hostname within the route53 zone: now, this is not too hard as the hostname is already correct in /etc/hostname. I just need to take this value and update the dns record. Not too fancy.
However, what I'm missing is how I can clean up Route53 when the server is turned off. I'm talking about the following scenario's:
- server is turned off correctly: What's the best place to put a script that only runs on shutdown?
- sudden IP change: Maybe there was a network interruption and we might have received a new IP address via DHCP. Is it possible to integrate my script with DHCP somehow?
- server lost power: maybe there was an issue at the region AZ, and we lost power. Maybe the instance is destroyed? I don't want the DNS records of those servers around in my DNS zone. Inactive servers should be removed from DNS after a few hours.
My greatest frustration is that DHCP + Dynamic DNS already solves most of those issues. However, dynamic updates via DHCP don't work with private Route53 zones.
Any suggestions?
Ask for a feature request to clean up Route53 records tied to the instance on termination. I'm also envisioning some kind of DNS monitor server that maybe does a ping to all servers listed in DNS, if one doesn't respond after 5 pings remove the record from Route53.