Many of us (including me) get confused with Amazon AWS product lines like S3 / Cloudfront and how to use them effectively and to our advantage. If you know how to use them effectively it can actually reduce your cost dramatically giving better user experience.
When I first started using Amazon S3, I thought it is not only storage of your static content but should also be used for data access. As I dig deeper into CDN’s (Content Delivery Networks) I realized that S3 is not the ideal way to access your content but you should use Amazon S3 to store your valuable data and use Amazon’s CloudFront to distribute the data.
First of all let me tell you what Content Delivery Network and CloudFront is?
Let us take an example of CodeItWell.com. I host my sites with thePlanet and my server is located in US. I am in India and when I request a page from my site the page loading time for me will be relatively higher than a person in US because of the geographic distance between India and US. Now suppose if I could mirror my site here in India or some place more close to my geographic location the page would load much faster. Content delivery network does exactly that. They have servers across the world and deliver the content from the shortest route between the hosted site and the end-user.
CloudFront by Amazon is one such Content Deliver Network.
How CloudFront and S3 are different?
S3 as the name suggest is simple storage service and so you can store your content online. CloudFront is the service to deliver the content stored on S3. I hope this makes it very clear about the objective of both the services i.e. S3 and Cloudfront.
Why two different Services aka S3 and CloudFront?
The answer is simple. You may store lot of content including some of your local hard disk content as well but you may not distribute all of that content. By having 2 independent services you have the power to store lot of content and use the one you want to be delivered to your end user but if you want to use Amazon S3 to distribute the content you can do that as well. See how here. This is what I did to start with and thought this is how it should have been done.
How to use CloudFront?
I will be using Amazon Console App for the step by step guide on using CloudFront and I assume that you have an Amazon S3 account and are aware of the process of creating buckets and uploading files to Amazon S3.
1. Creating Distribution for Your Amazon S3 Buckets.
Let me take the example of Go4Expert.com bucket imgs.g4estatic.com. I prefer to name the bucket same as my CName URL’s because that was a requirement for using S3 as distribution with your own custom URLs and so I do the same here as well.
Once you visit Amazon CloudFront Console App and click Create Distribution you will see.
Select the Origin S3 Bucket for which you would like to create the CloudFront Distribution Channel and enter your CName of your domain.
2. You after you save the above distribution the status of your distribution will be In Progress and you need to wait unless it shows as Deployed.
3. After the status becomes deployed you will have a unique CloudFront.net Domain Name for your distribution.

4. If you have opted for a CName you need to create the CName for your domain. In my case g4estatic.com is registered at GoDaddy and so I go to DNS control for the domain and setup a new CName for my domain i.e. imgs and target that to the Domain Name value in Amazon.

What should I use Amazon S3 or Cloudfront?
I think this question will be bugging your mind and the short answer is CloudFront and the main 2 reasons is – Gain faster access to your content and at a reduced price.
CloudFront Servers are spread across the world and content is always served from an Amazon server that is closest to the user’s location thus improving the page loading time as it means fewer network hops.
Amazon S3 charges $0.01 per 10,000 requests where as CloudFront price is many times lower that that. It is only $0.0075 – $0.0095 per 10,000 HTTP Requests. CloudFront Bandwidth pricing is same as S3 pricing to start with but lowers much faster than S3 Pricing and so you are bound to save some bucks on bandwidth as your usage goes higher when compared to S3.
If you have any queries share them in comments below and I will be more than happy to help.
But if you are not planning to subscribe through Email. Try subscribing to RSS.




{ 18 comments… read them below or add one }
I always enjoy learning what other people think about Amazon Web Services and how they use them. Check out my very own tool CloudBerry Explorer that helps to
manage S3 and CloudFront on Windows . It is a freeware. http://s3.cloudberrylab.com/. It allows managing CloudFront streaming and private distributions, generate links and html code.
I just HAD to leave a comment, for the simple reason that between your two posts – the one on setting up the S3 service and the one on setting up CloudFront, I was able to spot what I had done wrong over a week ago, resolve the issues I had created with the site and get it working in a fraction of the time.
THANK YOU for the clarity. Much appreciated.
The pleasure is all mine.
Thanks Shabbir for the detailed info how to set the amazon cloudfront with CNAME. I was struggling for the past two day to get it work using my domain narticle.com and your article just lit up the lights. I was able to upload my files via my CNAME using the w3 total cache plugin. It just worked as a charm. Thanks again.
Ivan, the pleasure is all mine.
Thanks so much for the article. Very easy to follow. I was at first looking at setting up a cname for my S3 account and saw you link through to this cloudfront post.
Whilst the site I am working with at the moment only targets traffic from Australia – so I am not sure of cloudfront is worthwhile for it – I am wondering if it will be a problem if I setup a cname now for the S3 account and later want to start using cloudfront with other cnames? I read that for the s3 account you may only have one cname pointed at it. Is this the same with cloudfront? If I were running content for 2 different sites via cloudfront, linked to the one S3 account, would I be able to setup a cname for each of them?
Yes you can have multiple cloudfront content delivery with one S3 account. I do the same for majority of my forums and blogs.
Great information, Shabbir! I’m so glad I found your article at this point as I’m just venturing into S3/CF. In fact, I wasn’t even thinking CF until I read your thoughts and experience on the matter. Perfect for my situation.
I added CF and then it took no time at all to rework the few empty initial buckets I set up on S3 and then link up the new ones to CF distributions. I’m glad I found all that out now–at the beginning! Now I’m off to the (major) task of filling those buckets with content!
Thank you.
Jim, the pleasure is all mine.
Hi,
I have a question. I’ve just set up my S3 account and I’m right in the middle of trying to set up my first distribution channel, but I have no idea what the purpose of this CName stuff is. Do I have to use one? What are the benefits?
Cheers,
Rob…
Sorry, that should say that I’m in the middle of trying to set up my first distribution channel for my Cloudfront Account. Also, that it’s absolutely doing my head in.
Thanks…
Rob using a CName gives you the benefit of using better names instead of some junkie type id provided by Amazon. Apart from that you can make the domain cookieless so no cookies are setup from that domain and this can save you some header’s size being sent in each request by the browser.
Awesome, much appreciated!
For sake of speed (of the setup process), I’ve elected to go without for now. But definitely appreciate your help.
Rob…
The pleasure is all mine Rob and yes CNames can take some time to propagate.
Great article. You write very informative articles that have saved me hours of work on S3 and CloudFront.
Hello and thank you for the fantastic information.
I still have a doubt though and it is the following.
In my case, that I decided to use cloudfront for streaming audio, is it MANDATORY for me to use Amazon S3/cdn or can I store my files somewhere else?
I have read that both amazon services are cost effective, however I read of free CDN services, like coralcdn.org (ANY THAT you can recommend?)
Thank you in advance
Manu
Manu, free CDN I have not tried coralcdn and so cannot comment on them.
Regarding S3 you have to store the files in Amazon but if you use MaxCDN ( imtips.co/go/maxcdn Aff Link ), you can host your files on your server and CDN pulls them. I use MaxCDN here at imtips.co