How To Host a Static Website on S3 Using a Second Level Domain

, Wellesley, MA

Last week, Amazon added support for using second level domains for static websites hosted on S3. The instructions in Amazon’s blog post misled me, and it sounds like Dave Winer was similarly confused. To clarify, their instructions describe how to redirect a second level domain to any other domain. What I actually want, and what the new feature also enables is serving my website content directly from my second level domain. Here are the steps to do that instead:

  1. Create an S3 bucket for your second level domain, e.g., matthewlmcclure.com.

  2. Enable website hosting, and enter an index document name, e.g., index.html.

  3. Add a bucket policy. Copy, paste, and edit the sample policy, replacing example-bucket with the name of your second level domain bucket.

  4. Upload your website content to your second level domain bucket.

  5. Create an A “Alias” DNS record in Route 53. Name it the same as your second level domain name, e.g. matthewlmcclure.com, and select the S3 website endpoint corresponding to your second level domain from the menu that appears when you click the Alias Target field. This is the key step that enables the new feature. A “Alias” records appear as though they are normal A records to resolvers, and Route 53 directs requests to your S3 bucket.

A Alias

  1. If you previously hosted the same content on a subdomain, e.g., static.matthewlmcclure.com, redirect requests for the subdomain to your second level domain. In the bucket properties for your subdomain, select Redirect All Requests to Another Host Name and enter your second level domain in the Redirect All Requests To field.

S3 Redirect

The instructions in Amazon’s S3 developer guide should produce the same results, but the steps in Amazon’s blog post would do the opposite.

Enjoyed reading this post? Discuss it on Reddit, or follow me on Twitter.