ACG Cliff Notes: CloudFront 101

Ford Prior
3 min readAug 22, 2018

--

In addition to data centers (i.e. AZ’s) scattered across AWS Regions, they’ve got something called “Edge Locations” that are strategically placed to optimize internet traffic originating from AWS servers.

So…what’s CloudFront?

It’s a content delivery network, or CDN. A CDN is just a clever way of caching content closer to the clients requesting it, instead of storing it exclusively on its origin server (which may be 10,000 miles away).

Here are some key definitions:

  • Edge location — where it’ll be cached (see above)
  • Origin — origin of where all the files that the CDN will distribute (e.g. an S3 bucket, EC2 instance, ELB, or Route 53…but usually not Route 53).
  • Distribution — a CDN network you create consisting of edge locations

How does it work?

Basically, you create a distribution and add a resource to it. The distribution will give you a special “edge URL”, which you’ll use in your application.

More key terms:

  • Web distribution — a special distribution for websites
  • RTMP — a special distribution for Media Streaming (Adobe, Flash, etc.)

Extra facts:

  • CloudFront provides PUT capability (i.e. writing).
  • TTL is however long object will be cached (e.g. 24 hours)
  • You can clear objects (e.g. clear the cache within 24 hrs. TTL) so users see the latest version, you will be charged.

The Lab!

  1. OK, first thing: create a bucket. Name it my-crazy-asian-bucketand put it in the Asia-Pacific (Seoul) region.

2. Now, add a big JPEG to it, maybe on of your face. 👏Yay! Now, there’s a photo of your face sitting in a datacenter in Seoul!

…but, because it’s in Asia, it’ll take forever to retrieve! 😢 Think of all those undersea cables it has to zip through!

TIL there’s no cables running through the USA. Or Canada. Or Mexico!

3. Now, go to CloudFront and click a “Create Distribution”, then click “Get Started” under Web.

Use these Origin settings:

Use these Default Cache settings:

And use these Distribution settings:

It takes a looooong time (15 minutes), so get some coffee or do a happy dance 💃!

Look! It’s done! 👇

Here’s a look at the Distribution page:

NOTE: If you’re Donald Trump and want to ban, say, 5 mostly-Muslim countries 🙄, from accessing your content, AWS has a special feature for blacklisting specific countries! 👇

Now, paste CloudFront domain into your URL, add append the name of your S3 object with your face on it (which is sitting in Seoul). Look how quickly it loads!

--

--