S3 hosting & naked domains

For a while, I had been tempted to move the hosting of my static websites (including this one) to Amazon’s S3 storage service, which has been able to serve up websites for a while. One sticking point was that it wasn’t easily possible to use a “naked domain” as the URL to access the site. That is, it was easy to use DNS CNAME records to point URLs like http://www.kaivonfintel.org to an S3 “bucket”. But you couldn’t do that with the naked domain http://kaivonfintel.org. There were more or less ugly workarounds that I wanted nothing to do with.

Now, my DNS provider of choice, DNS Made Easy, has come up with a technology they call ANAME records (not to be confused with the standard A records). With this, naked domains on S3 are now possible. There is a tricky bit, though. All of the “hosting a static website on S3” tutorials on the net have you name your S3 bucket “foobar.example.com”, that is, using a non-naked domain. That is because otherwise S3 wouldn’t know what to do with an incoming request for that domain. If, however, you now wish to go the DNS Made Easy ANAME way, and want to host a naked domain on S3, the bucket has to be named “nakedly” so to speak: “example.com”. Then, an ANAME record can point http://example.com at the S3 bucket. Here is the relevant DNS record for this site:

kaivonfintel.org. 60 IN ANAME kaivonfintel.org.s3-website-us-east-1.amazonaws.com.

This means that if you have an S3 bucket named the old way, you have to create a new one named the naked way and re-upload your content to that new bucket. (S3 doesn’t allow you to rename a bucket.)

Another thing that took a bit of fiddling was to redirect traffic from http://www.kaivonfintel.org (if anybody ever tried that) to the naked domain. Turns out that again S3’s (in)capabilities mean that a workaround is needed. I have another S3 bucket named “www.kaivonfintel.org” and a CNAME record pointing traffic to the www address to that bucket. Its only content is a simple html redirect file that sends browsers straight to the naked domain.

As you might have guessed, I figured this out the hard way, through trial and error, since I hadn’t found a tutorial on this topic. If this is all gobbledegook to you, good for you. You probably have better things to think about.

Written on Permanent link to this article.