Amazon CloudFront – How To Setup CloudFront To Work With S3

Advertisement

Assuming you run a high trafficked website or blog and you ran in to these following problems:

  • Slow content serving – Contents (htmls, images, download files) are serving at extremely slow speed, especially during traffic spikes
  • Paid, and unused – You are paying you web host more than what you are actually utilizing. That means, you are probably paying for a web hosting package with 50Gb of web space and 1Tb of bandwidth, but you are barely using half of them.
  • Messy files/folders – The web account is in a mess. Images folders, download-able item folders are not properly organized.

All these can be easily solved with Amazon CloudFront. CloudFront is a new service launched by Amazon, powered by cloud computing technology. Using Amazon S3 as storage, CloudFront serves on top of the buckets and deliver contents at a much higher speed with lower latency. Click here to read more.

If you are already using Amazon S3 to serve files for websites, CloudFront is really something you should check out. We’ll now guide you through setting up CloudFront to serve web files.

  1. First and Formost

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

  2. Create Distribution

    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 previous has this following asset:

    • http://media02.hongkiat.com/folder1/imageA.jpg, it now can be accessed with the URL
    • http://XXXXX.cloudfront.net/folder1/imageA.jpg

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

  3. Create CNAME

    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 simplier, 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://media02.hongkiat.com/

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

    This might take 24 hours to propagate, but in the mean time, filled up the CNAME in S3 Firefox.

    Once it’s properly propagated (you can test with pinging the URL), you can serving files using http://media02.hongkiat.com/*.

  4. Performance Comparison

    We all know how fast and efficient Amazon S3 serve files, but we thought you should see a comparison after CloudFront is being implemented on top of the serving so you’ll know each and every penny spend is worthwhile. To do a fair compare of the loading speed differences, we took a blog content, load it twice; once with images hosted under hongkiat.s3.amazonaws.com, another time with images under static.hongkiat.com (CloudFront) and monitor it with Pingdom Tools. Click on images for larger view.

    hongkiat.s3.amazonaws.com – 41 images loaded at 6.5 sec.

    static.hongkiat.com (CloudFront)- 41 images loaded at 3.5 sec.

Related Contents

Sponsors

Posted by hongkiat in How-To , at 11.22.08

Tags: , , , , , , ,

Comments

  1. Dave November 22nd, 2008

    Thanks for your post, it was very informative! One small question; I’m not currently using S3 but it’s very appealing to me, if I want to make use of Cloudfront, should I get a S3 account first and then Cloudfront as an add-on, or will this happen automatically?

    Thanks!

    -Dave

    Reply
  2. Dave November 22nd, 2008

    Right, I completely messed up my question there. You obviously answered that at step one. I found out the answer to my actual question on the cloudfront information page, so you can kindly (I beg of thee, it’s 3am here, I’m not thinking straight! Please!! ;) ignore my previous comment.. ahem.

    Signed up for S3, looking like the perfect solution! Thanks!

    Reply
  3. Rahul November 22nd, 2008

    Well, I would love to use this service if i require.

    Now this is what I love @ hongkiat. Such good explanation so that a newbee can also know what to do and how to do it without any errors.

    Thanks and cheers to Hongkiat.com

    Reply
  4. ncus November 23rd, 2008

    woot this is super. Exactly what kind of article I am looking for. I am looking for a new host for my images.

    Reply
  5. Ana November 24th, 2008

    Excellent article. I sort of use S3 to serve some of my files, but found some images were not loading properly sometimes. I am definitely going to use the CloudFront now.

    Reply
  6. sleepyguy November 25th, 2008

    Thanks… this how to is exactly what i needed. Why didn’t Amazon put these directions on their resource site. Geez. Thank hongkiat!

    Reply
  7. Curtis December 18th, 2008

    Thanks for putting this together. Worked like a charm.

    Reply
  8. Daniel January 3rd, 2009

    Thanks for a nice guide, it made it easy to implement a couldfront solution.

    Reply
  9. Andy January 8th, 2009

    Great and very informative post! If you are on Windows try CloudBerry Explorer for Amazon S3 FREEWARE. It makes managing files in S3 and CloudFront EASY http://cloudberrylab.com/

    Reply
  10. Woodstock Real Estate January 25th, 2009

    I had no idea it was that easy. Thanks hong!

    Reply
  11. cloudberrylab.com March 26th, 2009

    if you want to explore Amazon S3 online storage and configure CloudFront CDN I suggest that you try CloudBerry S3 Explorer Freeware

    Reply
  12. Sid April 21st, 2009

    hi,

    I have a question. Once you start using amazon cloudfront do you really need web hosting services. I have most of my sites with dreamhost.com and I notice now they offer cloudfront at 3.95/month.

    I understand that amazon will serve files much faster and seamlessly, if that is the case why do you need webhost and why can’t we just host with amazon.

    I would appreciate your insight into this.

    thanks,

    Sid

    Reply
  13. Mark Wilhelm August 22nd, 2009

    Sid, Amazon.com won’t parse any dynamic files. Just static ones. So no PHP scripts would work, no CGI, and you wouldn’t have anywhere to run a MySQL database. That’s why hosts are still important. ;)

    Reply
  14. ヴィトン 財布 ダミエ January 7th, 2010

  15. sesli sohbet forum February 16th, 2010

    This is a quarterly growth figure. It is standard practice in the United States to report growth data on an annual basis.

    thanks admin

    Reply

Leave a reply