In the words of Amazon, Amazon S3 (Simple Storage Service) “is storage for the Internet. It is designed to make web-scale computing easier for developers”. Developers (including this one) use it to store stuff in ‘the cloud’. You *could* host a file on your own server, but your own server and configuration probably isn’t as fast, reliable, secure and scalable as Amazon’s infrastructure. And by ‘probably’ I mean ‘definitely’. S3 storage is also cheap (quite possibly cheaper than going the DIY route as you only pay for what you use) which makes it a no-brainer in most cases.
It’s easy to get confused by all the jargon and acronyms… AWS, S3, Buckets, Objects… but I’ll attempt to clear things up in layman’s terms:
- AWS = Amazon Web Services or as CNN puts it, “Amazon’s $160 billion business you’ve never heard of”
- S3 = Root folder
- Buckets = Sub folders
- Objects = Files
Once you set up an S3 account, you’ll get your own little space on Amazon’s servers. You can then set up buckets and upload objects to those buckets. You can then access the files by going to a url such as http://region.amazonaws.com/bucketname/filename
That’s it. Simple storage by name, simple storage by nature. The problem with the default url structure however is that it’s not very pretty. Not only do urls tend to be quite long, they’re also Amazon branded.
On one of my own sites (theleavingcert.com) we have thousands of exam papers and marking scheme pdf documents. S3 storage was perfect to host these, but I was reluctant to start linking to something like http://exampapers.s3-website-eu-west-1.amazonaws.com/english/2010-exam-paper.pdf.
I wanted a branded url so that users wouldn’t have any clues that the papers were hosted on Amazon. If users shared those urls or if another site started scraping those urls, it would result in no recognition from the source they were first discovered (our site).
What I wanted was to create a link such as http://papers.theleavingcert.com/english/2010-exam-paper.pdf. That way, it’s immediately obvious where the papers come from (theleavingcert.com)… the url is also shorter and more readable. “s3-website-eu-west-1.amazonaws” is useless information as it doesn’t give any explanation as to what the file is about. At least with ‘papers.theleavingcert.com’, you can guess what the link will be about before you visit it – or at least our target audience can (Irish second level students know that ‘the leaving cert’ is the name of the final state examination students take before heading off to college or going to work).
So how do you go about achieving that type of branded url? I’ll explain below…
Step 1: Register / Login
If you don’t have an Amazon Web Services account, you can set one up for free. Once set up and logged in, you’ll have access to the AWS Management Console which can look very intimidating at first glance. All you need to focus on for now is ‘S3’.
Step 2. Create a bucket
Once you click on S3 from the menu, you’ll be able to create a bucket by giving it a name and selecting a region. The name is more important than you might think. You can’t rename a bucket, therefore you need to choose the name carefully. In order to get your branded url working using this guide (benefits of which I explained earlier), you need to give your bucket the same name as your own domain name.
For example if you own a site called “helloworld.com” and want to host images and media using an S3 bucket, but with a url such as media.helloworld.com/myfile, then you need to give your bucket name the name of “media.helloworld.com”. If you just name your bucket “helloworld” or “helloworld.com”, this guide will not work.
Step 3. Upload files, make them public
Once your bucket is set up, you should be able to upload files. By default, both your bucket and your files aren’t publicly accessible. You need to make them publicly accessible by right clicking on the file / folder and selecting ‘Make Public’.
Step 4. Modify DNS Settings on your domain name
You need to create a new CNAME entry for your domain. This involves going to the place where you registered your domain name (aka your domain registrar) and changing the DNS settings. Sticking to my earlier example, I’ll create a fictional CNAME record below:
Name: media (what our subdomain is called)
Value: media.helloworld.com.s3-website-eu-west-1.amazonaws.com (note the format is: “bucketname”+”region”+”amazonaws.com”)
Step 5. Test you can access files
It can take a few hours for those DNS settings to kick in, but when they do you should be able to access your files in a couple of different ways: