Amazon CloudFront

Filed Under: AWS
Request Flow Of Cloud Formation

Amazon CloudFront is a Content Delivery Network (CDN) on AWS Cloud. A content delivery network refers to geographically distributed servers to provide the faster response of content over the internet.

The popularity of the content delivery network (CDN) grown up in recent times. Its ability to serve content faster makes it a good choice over making requests to the origin servers. These days the majority of web traffic is served through CDNs, including traffic from major internet service providers like Amazon, Facebook, and Netflix.

Amazon CloudFront took the content delivery network (CDN) to another level. It has 166 points of presence (PoPs) across the world which is massively scaled and globally distributed.

What is Amazon CloudFront?

Amazon CloudFront is a web service in AWS cloud that provides the content delivery network (CDN). Amazon has the worldwide network of data centers often known as edge locations. CloudFront delivers the static and dynamic content such as .js, .html, .css, .js and image files. CloudFront speeds up the distribution of the content.

So, how they do it?

If you have the idea of the content delivery network (CDN) then you must know how all this works. Let’s take an example of request – When a user requests a content that is being served with CloudFront, the user is routed to the nearest edge location which has very low latency (Latency is the time delay in request completion).

  • If the requested content is available at edge location with low latency, CloudFront delivers it quickly.
  • If not then the content would be retrieved from the origin location (Amazon S3, Http Web Server etc.)

Why Amazon CloudFront?

If you know the use cases of the content delivery network (CDN) then you know the importance of the CloudFront. AWS adds a few things on top of the traditional content delivery network. CloudFront is massively scaled which makes it reliable and popular among AWS users.

1. Security

Amazon CloudFront is a highly secured content delivery network (CDN) provides both application and network level security. AWS Shield, AWS Web Application Firewall (WAF), and CloudFront create layered security with Amazon Route53.

These layers protect against multiple types of attacks including network and application layer DDoS attacks. DDoS is one of the very popular security attacks on a content delivery network (CDN). Please let me know in comments if you want to understand DDoS attacks and prevention in detail.

2. Fast Performance

The content delivery network (CDN) is primarily designed to provide fast performance. CloudFront’s nature to store data on edge location with very low latency makes it faster than any other CDN.

Amazon CloudFront is running on the AWS network backbone. Which makes it highly efficient between CloudFront Edge locations and other AWS services, across regions and applications.

3. Global Availability

As mentioned earlier CloudFront has 166 points of presence (PoPs) across the world which is massively scaled and globally distributed.

Amazon CloudFront usually delivers content from the edge location rather than the original location of the content. CloudFront also allows you to set up multiple origins to enable redundancy in your backend architecture.

4. Programmable and DevOps Friendly

AWS provides the API to connect for almost all of its service on the cloud. Amazon CloudFront provides developers with a full-featured API to create, configure and maintain your CloudFront distributions.

You can find the API documentation of the CloudFront here:

https://docs.aws.amazon.com/cloudfront/latest/APIReference/Welcome.html

5. Cost Effective

Amazon CloudFront is a very cost-effective service on AWS. It also comes in the free tier as well, so, you need not pay if you are a beginner or tech enthusiast and just want to see how things work.

Below is the cost model that AWS provides:

Cloudfront Cost Model

Cloudfront Cost Model

Note: If you are going to heavily use the CloudFront then you can also talk to the AWS team for the discount.

How CloudFront Works?

There are two aspects of Amazon CloudFront of how it works.? First is storing the content on edge location and replicating that to other edge location. Second, the retrieval of content from edge locations and from the origin location.

1. Setup CloudFront to deliver content

You create a CloudFront distribution with the origin where you want to store the static and dynamic content like .js, .html, .css, and images. The origin of content could be an Amazon S3 bucket or an Http Web server.

Amazon CloudFront sends the content to its edge locations ie. edge servers. Let’s see how to configure your CloudFront:

  • Origin Server: Specify the origin server of location of the content.
  • Upload Content to Origin: Now, upload files to your origin server. Files also known as objects, typically includes web pages, images, and media files, can be anything that can be served over HTTP (No other than HTTP complaint content).
  • Create CloudFront Distribution: Create CloudFront distribution to specify the content origin location. The origin will be used to get your files from when users request the files through your web site or application
  • Domain Creation: CloudFront will assign a domain for your new distribution that you will be using in place of origin url.
  • Distribution Configurations: Once the CloudFront distribution has been created, CloudFront will send the distribution configurations to all of its edge locations. CloudFront caches will cache the objects.

Please see the below diagram to understand the CloudFront request flow (Source: Amazon Web Service):

Cloudfront Request Flow

Cloudfront Request Flow

2. How CloudFront delivers content?

After configuring your CloudFront distribution you can use the CloudFront URL for the content delivery.

  • A user access the content or requests to a website page
  • Domain name server (DNS) routes your request to the CloudFront edge location that is nearest in terms of latency
  • In the edge location, the CloudFront checks the cache for the requested content. If the content available then returns else it follows:
    • CloudFront sends the request to the origin server
    • The origin server retrieves the image and sends it back to the CloudFront edge location.
    • The origin server retrieves the image and sends it back to the CloudFront edge location. CloudFront also adds the files to the cache in the edge location for the next time someone requests those files.

Amazon CloudFront Use Cases

There are several use cases of CloudFront, especially wherever the website acceleration is required. As we know that CloudFront is the content delivery network so all the applications of CDN are also the use cases of the CloudFront.

Below are the few of many use cases of CloudFront on AWS:

1. Live Streaming Videos

CloudFront offers many options to stream your videos faster which includes both stored videos as well as the live videos or events.

Amazon CloudFront streams in all common formats such as MPEG DASH, Apple HLS, Microsoft Smooth Streaming, and CMAF, to any device.

2. Accelerate Website Content

CloudFront can drastically improve the performance of your website content by caching the content. It reduces the steps to reach to your data since its cache mechanism holds the content data at edge location.

To simply demonstrate how things work:

Request Flow Of Cloud Formation

Request Flow Of Cloud Formation

This is very popular among the AWS users that Amazon S3 + Amazon CloudFront: A Match made in Cloud.

3. Customize at the Edge

CloudFront opens up a number of possibilities when you run the serverless code like Amazon Lambda functions. For Example, You can configure a number of error messages and specific content in the response of the errors. Or you can use a function to help authorize users and control access to your content before CloudFront forwards a request to your origin.

In our next post, we will talk more about the CloudFront setup with Amazon S3 with a static website.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages