How To Setup Amazon CloudFront To Work With S3

See Part 1: Amazon S3 & PHP to Dynamically Store Files with Ease

If you currently have a site with high traffic, and would like to use a web service for content delivery, then Amazon CloudFront is what you need.

Amazon CloudFront delivers your content using a global network of edge locations. Requests for your objects are automatically routed to the nearest edge location, so content is delivered with the best possible performance. Amazon CloudFront works seamlessly with Amazon Simple Storage Service (Amazon S3) which durably stores the original, definitive versions of your files. Like other Amazon Web Services, there are no contracts or monthly commitments for using Amazon CloudFront – you pay only for as much or as little content as you actually deliver through the service.

1. Get an Amazon S3 account, then sign-up for the Amazon CloudFront service. Check your email to make sure the service is activated for you.

2. Applications you use to manage Amazon S3 buckets might varies, but we’ll try to stick to a free tool – S3 Firefox, a S3 file manager with CloudFront supported. Get connected to your account with S3 Firefox, right click on the bucket name (assuming files and folders inside here are/will be web accessible) and choose Manage Distributions.

Distribution is an unique URL of sort that you can use to reference a file. You’ll get a better picture once it’s created. Click on Create Distribution to create your first distribution for the bucket.

Once you’ve created, you’ll noticed a new Domain Name: xxxxx.cloudfront.net is being created for you. Status will turn from InProgress to Deployed when it’s done. You can also click on the Refresh button to update the status.

If you previously used: http://bryan-hunsinger.s3.amazonaws.com/s3demo/image.jpg, it now can be accessed with this URL: http://XXXXX.cloudfront.net/s3demo/image.jpg

You still can serve files with the first URL but the latter one is CloudFront powered, and it’s way faster.

3. Distribution URL starts with http://xxxxx.cloudfront.net/ and we don’t think there’s any way to decide what goes before .cloudfront.net. However, to make the URL simpler, nice and easier to remember, we can use CNAME to map this URL to whatever we want. This requires access to web hosting control panels. In this example, we’ll show you how to map: http://XXXXX.cloudfront.net/ to http://static.bryanhun.com/

If you are unfamiliar with CNAMEs, we suggest that you ask your web host to do it for you. You’ll enter something similar to this, with your own distribution URL of course:

static – 14400 – IN – CNAME – xxxxxx.cloudfront.net.
www.static – 14400 – IN – CNAME – xxxxxx.cloudfront.net.

This might take 24 hours to propagate, but in the mean time, filled up the CNAME in S3 Firefox. Under Resource URL, you should have: http://xxxxxx.cloudfront.net and http://static.bryanhun.com, and for CNAME, you should have: http://static.bryanhun.com.

Compared to S3, CloudFront will take (on average) 50% to load. Good luck!

Tags: , , , , ,

Leave a Reply

You must be logged in to post a comment.