Map a custom subdomain to Amazon’s S3 service

Background

I’ve been dabbling with Amazon’s AWS S3 service lately for a number of reasons, but one of them is hosting web resources. I have been putting up outlines from my Sunday School lessons at Church which are easily taken care of with Dropbox through their sharing options. Then someone asked me to put up some audio from the lessons to listen to later and I knew that I needed a more robust solution. Not only would audio take up a huge amount of my Dropbox quote, but I also wasn’t sure about the bandwidth issues of either hosting audio from either Dropbox or my web hosting service. I had also been thinking about switching up my Church’s audio storage solution and this would be a great opportunity to test settings and get more familiar with the service.

AWS S3

I settled on trying Amazon’s S3 service largely because it is pretty cheap and I’m pretty sure that for some time to come I’ll fall in the free tier. People aren’t exactly waiting with bated breath for these mp3s (You can change that!). I also knew that you could map a subdomain to their service and that seemed like a really great way to add further credibility to your website.

The Nitty Gritty

I did some reading and came across some conflicting instructions on how exactly to do the mapping, so I will show you what I found worked. I will assume that your DNS hosting is already in place and that you have at least a basic understanding of CNAME records. I will also assume that you understand that S3 uses the concepts of “buckets” as your primary storage unit/object. Make sure you have a basic understanding of these things before you go any further.

There are really only two steps:

  1. Create a bucket with the same name as the subdomain you want to map to. The name of the bucket needs to match the name of your subdomain. If your subdomain is “cdn.mywebsite.com”, your bucket needs to also be named “cdn.mywebsite.com”. Amazon requires unique names anyway, so this won’t be a problem.
  2. Map your subdomain to your S3 bucket. Your CNAME needs to be mapped to that bucket, not just S3. The CNAME record must be pointed to “cdn.mywebsite.com.s3.amazonaws.com.” not just “s3.amazonaws.com.” (Pay attention to the periods at the end! They really do need to be there–1/9/2015 not needed in some dns management interfaces I’ve learned, apparently its assumed). This is where I found the conflicting instructions. Also notice that this is different from the static web hosting option that Amazon offers with S3 (which is a pretty sweet deal for static websites). You don’t need to have that enabled to do what is described here.

That does it! All you have to do after setting everything up is wait for the DNS settings to take effect–which varies from minutes to hours. You can now access the files in your S3 bucket from your custom subdomain.

Final Notes

If you haven’t already, you need to poke around into S3’s permissions settings. There are settings for buckets and files in the buckets. Obviously, you want full access, but you will probably only want the general public to have read access. Those can both be accessed and configured through Amazon’s AWS console.

Updates:

as of 1/9/2015

I have found an additional page that will help with the process straight from Amazon’s Documentation!

Also you need to enable website hosting under the ‘static website hosting’ section. You need to set a index document–which should probably something like index.html–but, s3 doesn’t seem to care what you put in there or whether the file even exists. Curious, but good to know.