CloudFront(CDN)-AWS Blog Info

CloudFront is a CDN (Content Delivery Network). It retrieves data from Amazon S3 bucket and distributes it to multiple datacenter locations. It delivers the data through a network of data centers called edge locations. The nearest edge location is routed when the user requests for data, resulting in lowest latency, low network traffic, fast access to data, etc.

How AWS CloudFront Delivers the Content?

AWS CloudFront delivers the content in the following steps.

Step 1 − The user accesses a website and requests an object to download like an image file.

Step 2 − DNS routes your request to the nearest CloudFront edge location to serve the user request.

Step 3 − At edge location, CloudFront checks its cache for the requested files. If found, then returns it to the user otherwise does the following −

  • First CloudFront compares the request with the specifications and forwards it to the applicable origin server for the corresponding file type.

  • The origin servers send the files back to the CloudFront edge location.

  • As soon as the first byte arrives from the origin, CloudFront starts forwarding it to the user and adds the files to the cache in the edge location for the next time when someone again requests for the same file.

Step 4 − The object is now in an edge cache for 24 hours or for the provided duration in file headers. CloudFront does the following −

  • CloudFront forwards the next request for the object to the user’s origin to check the edge location version is updated or not.

  • If the edge location version is updated, then CloudFront delivers it to the user.

  • If the edge location version is not updated, then origin sends the latest version to CloudFront. CloudFront delivers the object to the user and stores the latest version in the cache at that edge location.

Features of CloudFront

Fast − The broad network of edge locations and CloudFront caches copies of content close to the end users that results in lowering latency, high data transfer rates and low network traffic. All these make CloudFront fast.

Simple − It is easy to use.

Can be used with other AWS Services − Amazon CloudFront is designed in such a way that it can be easily integrated with other AWS services, like Amazon S3, Amazon EC2.

Cost-effective − Using Amazon CloudFront, we pay only for the content that you deliver through the network, without any hidden charges and no up-front fees.

Elastic − Using Amazon CloudFront, we need not worry about maintenance. The service automatically responds if any action is needed, in case the demand increases or decreases.

Reliable − Amazon CloudFront is built on Amazon’s highly reliable infrastructure, i.e. its edge locations will automatically re-route the end users to the next nearest location, if required in some situations.

Global − Amazon CloudFront uses a global network of edge locations located in most of the regions.

Key Terminology of CloudFront CDN

  • Edge Location: Edge location is the location where the content will be cached. It is a separate to an AWS Region or AWS availability zone.
  • Origin: It defines the origin of all the files that CDN will distribute. Origin can be either an S3 bucket, an EC2 instance or an Elastic Load Balancer.
  • Distribution: It is the name given to the CDN which consists of a collection of edge locations. When we create a new CDN in a network with aws means that we are creating a Distribution.

The distribution can be of two types:

  • Web Distribution: It is typically used for websites.
  • RTMP: It is used for Media Streaming.

How CloudFront CDN works

CloudFront CDN
  • Edge locations spread all around the world and currently, there are 50 edge locations.
  • When the first user requests to get the content, and the request goes to the nearest edge location. The nearest edge will be read first to determine whether it contains the cached data or not. If an edge does not contain the cached data, the edge location pulls the data from the S3 bucket. Suppose the S3 bucket is in Ireland. But this process is not quicker for the first user. However, when the second user accesses the same file, this file is already cached to the edge location, so it pulls the data from its edge location. It speeds up the delivery of the data.

Key points related to the CloudFront CDN

  • Amazon CloudFront CDN is used to deliver your entire website, including dynamic, static, streaming, and interactive content using a global network of edge locations.
  • When a user requests for content, the request is automatically routed to the nearest edge location so that the content is delivered with the best possible performance.
  • Amazon CloudFront CDN is optimized to work with other Amazon web services such as Amazon Simple Storage services (S3), Amazon Elastic Compute Cloud (EC2), Amazon Elastic Load balancing and Amazon Route 53. Amazon CloudFront CDN also works with the non-AWS origin server which stores original and versions of the files.

How to Set Up AWS CloudFront?

AWS CloudFront can be set up using the following steps.

Step 1 − Sign in to AWS management console using the following link − https://console.aws.amazon.com/

Step 2 − Upload Amazon S3 and choose every permission public. (How to upload content to S3 bucket is discussed in chapter 14)

Step 3 − Create a CloudFront Web Distribution using the following steps.

Get Started

  • Create Distribution page opens. Choose the Amazon S3 bucket created in the Origin Domain Name and leave the remaining fields as default.

Create Distribution

  • Default Cache Behavior Settings page opens. Keep the values as default and move to the next page.

  • A Distribution settings page opens. Fill the details as per your requirement and click the Create Distribution button.

  • The Status column changes from In Progress to Deployed. Enable your distribution by selecting the Enable option. It will take around 15 minutes for the domain name to be available in the Distributions list.

Test the Links

After creating distribution, CloudFront knows the location of Amazon S3 server and the user knows the domain name associated with the distribution. However, we can also create a link to Amazon S3 bucket content with that domain name and have CloudFront serve it. This helps save a lot of time.

Following are the steps to link an object −

Step 1 − Copy the following HTML code to a new file and write the domain-name that CloudFront assigned to the distribution in the place of domain name. Write a file name of Amazon S3 bucket in the place of object-name.

<html> 
   <head>CloudFront Testing link</head> 
   <body> 
      <p>My Cludfront.</p> 
      <p><img src = "http://domain-name/object-name" alt = "test image"/> 
   </body> 
</html>

Step 2 − Save the text in a file with .html extension.

Step 3 − Open the web page in a browser to test the links to see if they are working correctly. If not, then crosscheck the settings.

Comments

Popular posts from this blog

Amazon Route 53-AWS Blog Info

Introduction To Amazon Web services-AWS Blog Info

What is DNS(Domain name Services)-AWS Blog Info