In an earlier post I described a process for hosting static websites on Amazon’s S3 service. In that post, I described hosting a site from a single URL mapped to an S3 “bucket”. This prompted a question from a reader:
In this post, I’ll describe adding additional host names to our root domain (in this case, I’ll add “www.tubaday.org” to the “tubaday.org” domain) as well as how to forward one hostname to another.
If you have worked with Apache web hosting, you might do this as an alias (or redirect), but with the relatively limited options on Amazon S3 we can only implement a redirect from one S3 ‘bucket’ to another.
Configuring An S3 Bucket For Our New Host
In this case, I’m going to create a new S3 Bucket for my “www” domain. In the S3 Console, create a new bucket with the name of the URL (or host) you’d like to create.
This new bucket can be configured to serve any host as in the earlier post, but this will be a simpler case. We want to configure this bucket to redirect to our “root” bucket. Right click on the bucket and choose the Properties option.
This will open up the properties dialog. As before, select the Static Website Hosting option – but now rather than enabling static hosting, choose to Redirect all requests to another host name, with the appropriate redirect URL:
Save the properties, and your S3 host is configured. To test, if you open the Static website endpoint URL:
(NOTE: At this point you also want to keep that endpoint URL to configure later on – feel free to copy it to a notepad or clipboard!)
The URL should redirect you to the domain you entered in the ‘redirect’ box. If you want to create a host that doesn’t redirect – for example if you want to create an ‘assets’ URL, you could configure this to be a “real” host as well. In this case, we’ll keep the redirect option and configure this bucket to redirect
Creating a CNAME Record for Our New Host
Like we did previously, we want to configure DNS records so that our lengthy Amazon bucket URL becomes the short version we want for our domain. Access the Amazon Route 53 DNS service to find the records that we previously created for our domain. We’re going to want to add a new record reflecting our
www URL. Go to our previously created hosted zone:
And choose Go To Record Sets for our selected domain. We’ll want to Create a New Record Set for our domain.
The type of record set we want to create is a CNAME entry. Enter the name of the new host, and choose “CNAME – Canonical Name” from the drop down list.
The value we want to enter is the endpoint URL for the S3 bucket we created previously. (Did you copy that earlier? If not, go back to the S3 console to find it.)
Save the record set… and we’re done. As before, DNS changes may take awhile to propagate across the internet – but once this is done the
www record will serve as an entry to the
www.tubaday.org bucket created previously. When that bucket is accessed, it will forward the request to the root
(NOTE: You can also set up CNAME entries for ‘real’ buckets that don’t forward – with the caveat that you’ll have to configure bucket permissions, etc. as we did for the root bucket).