Friday, May 9, 2014

Amazon S3 Bucket custom DNS name

Amazon's S3 is an incredibly useful service for storing files and blobs of data. The data is stored in Buckets which are accessibly via an Amazon generated url, similar to:

http(s)://.s3.amazonaws.com/
or, for example, 
http://myFabBucketExample.eoinclayton.net.s3.amazonaws.com

The url does end up being a bit unwieldy though. You may also want to cover the potential future scenario of moving away from S3 and not having to deal with amazonaws.com urls littered throughout your code bases.
To deal with this, if you already have a DNS name (e.g. eoinclayton.net) you can map it to your bucket. To achieve this:

1. Create a bucket in S3 with the same name as you would like your DNS name to appear. E.g. I wanted to end up with a new "assets" subdomain, e.g.  http://assets.eoinclayton.net/{somefile}, so I made a bucket called "assets.eoinclayton.net":


2. If you want the bucket contents to be viewable by the public, modify the S3 bucket so that 'Everyone' has 'Open/Download' access to the contents

2. Next, go to your DNS provider to edit your DNS settings. My domain is held by easyCgi.com so I used their 'DomainCentral' portal to edit my DNS

3. Add a CNAME alias to point your new subdomain to the s3 bucket name


4. Wait a while for the DNS system to update itself and if all is well, you should be able to access your bucket resources directly, e.g.: http://assets.eoinclayton.net/GreenTick.jpg