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.
Further Reading …