In my previous article about hosting a static website on S3, I realize that I may have rushed past the section on DNS. The AWS Static Site Quickstart tool does most of what you need, but upon further review, I can say that it doesn’t do everything and it doesn’t do DNS particularly well. So let’s revisit Route 53 and run through some of what I’ve managed to piece together.
First, let me just say that I’m in no way a DNS expert. I’ve gotten pretty handy with some of the AWS tools but true DNS understanding eludes me. As much as I absorb, I just can’t seem to reason through how things should work and then get them to bend to my will, instead I focus more on trial-and-error. It’s embarrassing but it’s true.
In order to have a website hosted on S3 you’ll want a Route 53 entry. This is how you associate a domain name with where your site “lives,” be it a CloudFront distribution, an S3 bucket, a static IP, whatever. A Hosted Zone can be created in a second and costs $0.50 a month. Each website needs one unless you are handling your DNS with a different registrar.
Inside a Hosted Zone you have records. These are, as you guessed, your standard DNS records: A, CNAME, MX, SOA, NS, and so on. A website doesn’t work without these. The confusion — or at least my confusion — comes from how the setup of these seems to be a little bit of art and a little bit of science. Plus, it’s one of those things were there are “a number of ways to skin a cat” and getting a clear answer is never easy.
The Quickstart tool as well as domain purchases through AWS will handle your SOA and NS records on their own. SOA (Statement of Authority) is sort of the deed to the house. It outlines the name of the administrator, the amount of time a backup name server should wait before asking for updates, time-to-live (TTL) data, and so forth. It’s not something you need to mess with. The NS record includes the four (or more) name servers that are going to direct people to your site. Any host you use will provide these (Amazon included), and they will basically look like strange domain names.
Now, onto the stuff you will need to edit. The A Record connects the internet with the server. It commonly is populated with a static IP address, but things are rarely that simple with AWS. For our purposes I’ll assume you’ve initially setup your site as MySite.com, and will handle the www (and possibly other subdomains) after that.
Here’s the important part:
You’ll want to point your A Record for MySite.com at an Alias and then populate “Alias” with a CloudFront URL. It’ll look something like: randomnumbersandletters.cloudfront.net
. Then you will want to create a new record set with the name www.MySite.com, also as an Alias, and point it at the Cloudfront URL that you just used.
The Amazon setup docs are unclear on this, but it’s the simplest way to ensure that your domain works with or without a subdomains, that you can properly use CloudFront, and that you can later use some of the more advanced functions of S3, like Routing Rules.
Just make sure you have both MySite.com and www.MySite.com listed (on separate lines) as Alternate Domain Names in CloudFront to ensure that everything is working as planned!
I know it’s not a lot, but that’s what you need. A domain name, a hosted zone, four record sets (two A, NS, and SOA), and a CloudFront distribution. With that you can have a full functioning domain name pointing at a CDN’ed S3 bucket.
Sal December 18th, 2017
Posted In: AWS
Tags: Amazon S3, DNS, Hosted Zone, Hosting, Static Website