Just a few weeks ago, Amazon Web Services announced Failover DNS records in Route 53. I’ve played with them a little bit, and so far they’re amazing! This is useful because you shouldn’t need to worry about outages anymore. If a hosted zone were to go down, you could failover to a different AWS region (or another hosting provider). Here’s my quick start guide:
1. I’ve created 2 new EC2 micro instances and installed nginx on both. Ideally, you’d want to host these in two different AWS regions. Both of mine are in N. Virginia (oops!). I’ve customized the index.html files on each to display which server (Primary or Failover) they are running on. In this example, the primary server’s IP is 54.*.*.* and the failover is 50.*.*.*
2. Create a new Route 53 and add a domain to it.
3. We need to create a Route 53 “Health Check” (the link for this is in the left side navigation column) which pings the primary server (54.*.*.*). For this test, I am going to check that index.html is available using port 80.
4. Next, we need to create an A record (or CNAME) on the domain for the primary server. Note that we need to set the TTL to something shorter than usual. AWS recommends that you use 60 seconds so the switch happens as soon as possible. We also need to set the Routing Policy to “failover”. Since this is the primary server, I’ve selected “primary” and added the health check we created before.
5. Finally we need to add the secondary A record (or CNAME) for the failover server. The steps for this are just like the primary except under Routing Policy I’ve selected “Secondary”. You do not need to apply a health check to this one. (This won’t work if you apply the same heath check to both records);
Alright, everything is setup. Browsing to davekz.com shows us that we are hitting the primary server. Now let’s pretend something bad happens to primary server. For this example, I’m going to stop the nginx service on the primary box.
If you were to quick jump back to the site, you’d see that the request times out. Hopefully, after ~60 seconds, the DNS is updated and the failover server is now set as the primary. www.whatsmydns.net is a great tool to check the propagation of the DNS change.