I deploy websites frequently enough that I really should understand DNS thoroughly, but infrequently enough that it is hard to remember all the details between deployments. This blog post is as much for my future reference as anything else.
For my most recent project, I decided to use Amazon Route 53 for DNS, mostly for the experience of it. Route 53 offers a lot of great features, and is particularly easy to use when integrating with other Amazon Web Services products (EC2, S3), but is not quite as user friendly as other DNS products.
The setup I want is simple: the core domain (jcgaas.com), both with and without the common but unnecessary
www. subdomain, to map to the same static webpage hosted by Amazon S3.
Additionally, I need an
api. subdomain to point at a server I have hosted with an IPv4 address.
There are four types of records required to make this setup work. A fifth is needed to get IPv6 support. Two of them, the SOA “Start of Authority” and NS “Name Server” record, are set by Route 53 automatically.
The other two are ‘A’ records and CNAMEs.
The A record maps a domain or a subdomain to an IPv4 address.
So, for this setup, I need 2 ‘A’ records; one mapping the domain to the Amazon S3 endpoint (which Route 53 conveniently does for you as an ‘Alias’ record), and one mapping the
api. subdomain to the API server’s IP address.
An ‘AAAA’ record is for an IPv6 address, an additional AAAA record could be defined to map the
api. subdomain to the appropriate IPv6 address.
The CNAME (“canonical name”) record aliases a domain to another domain.
In this case, I use it to make the
www. subdomain an alias for the core, subdomain-less domain.
Many DNS systems offer a built-in way to redirect the user to another domain, for example making
www. send a
301 Moved Permanently HTTP status code referring to the unadorned domain.
Apparently, this is not a part of the DNS spec, and Amazon Route 53 does not implement such functionality directly.
For Route 53, the way to do this is to make the CNAME for
www. point to an Amazon S3 bucket for
www.<domain>, then set the S3 bucket to redirect all requests to the unadorned domain.
The net result is the same as other DNS system’s redirect functionality, just requires an extra step to set up.