CloudFront is a web service that speeds up distribution of your content. It delivers that content through a worldwide network of servers. When someone requests conten from CloudFront they are routed to the closed edge server to them to retrieve the content.

The number of networks and the distance that the request has to travel will have a significant impact on the performance, reliability, and availability of the asset.

Origin Servers

An origin server is the location where you store the original content.
This can be an EC2 instance, an S3 bucket or your own http server.

CloudFront will serve cached copies of your assets when available on the edge server. Otherwise for the first request to an edge server CloudFront will make a request to your origin server to cache the asset.

Amazon CloudFront helps improve performance of your website by:

You can use a CloudFront to deliver your entire website, including both static and dynamic content. You can control multiple origin servers and caching properties for different urls on your webiste.

Good choice for when you want to distribute updates or other downloadable software to end users. It also offers lower prices than Amazon S3 at higher usage tiers.

This is a great option for delivering media files. Lower data transfer prices and higher data transfer speeds.

Distribution

After choosing your origin server you can create a distribution. A distribution tells cloudfront where your files are. cloudfront will give you a unique domain name that you can use to reference your files.

E.g. if your origin is an S3 bucket http://mybucket.s3.amazonaws.com/images/image.jpg you would change your links to point to http://mybucket.cloudfront.net/images/image.jpg

You can also configure a CNAME so that you can serve the assets right from your own domain.

There are 2 types of distributions:

  1. Download distribution: deliver content via http or https.
  2. Streaming distribution: delivers content via RTMP.

Expiration

File expire after being in an edge location for 24 hours. After expiration, the next request for that content will be forwarded to your origin.

Steps

  1. Choose origin server.
  2. Create a distribution.
  3. Update your site to point asset urls to the cloudfront domain.
  4. ship it?

CloudFront vs Amazon S3

S3 is designed for long term durable storage. CloudFront is designed to distribute your popular content with low latency. It is not durable. CloudFront can be a more cost-effective way to deliver popular assets to end users.

comments powered by Disqus