Implement CloudFront using Edge Locations in an Application running in AWS Cloud Infrastructure

David Lourenço
4 min readMay 2, 2023

--

Note:
This paper, was created as an improvement of another solution developed and documented here. Please take a look for more context.

Implementation Must Have Concepts :
In this section, some significant concepts are clarified for the understanding of the implementation described below.

Edge Locations — Edge locations are AWS data centers designed to deliver services with the lowest latency possible. Amazon has dozens of these data centers spread across the world. They’re closer to users than Regions or Availability Zones, often in major cities, so responses can be fast and snappy.

CloudFront — Amazon CloudFront is a web service that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to your users. CloudFront delivers your content through a worldwide network of data centers called edge locations. When a user requests content that you’re serving with CloudFront, the request is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.

How CloudFront delivers content to your users

After configure CloudFront to deliver your content, here’s what happens when users request your objects:

  1. A user accesses your website or application and sends a request for an object, such as an image file or an HTML file.
  2. DNS routes the request to the CloudFront POP (edge location) that can best serve the request — typically the nearest CloudFront POP in terms of latency — and routes the request to that edge location.
  3. CloudFront checks its cache for the requested object. If the object is in the cache, CloudFront returns it to the user. If the object is not in the cache, CloudFront does the following:
  • 3a— CloudFront compares the request with the specifications in your distribution and forwards the request to your origin server for the corresponding object — for example, to your Amazon S3 bucket or your HTTP server.
  • 3b — The origin server sends the object back to the edge location.
  • 3c — As soon as the first byte arrives from the origin, CloudFront begins to forward the object to the user. CloudFront also adds the object to the cache for the next time someone requests it.

Create CloudFront Distribution

Cloud Front also known as Content Delivery Network is a web service that speeds up distribution of static and dynamic web content, such as .html, .css, .js, and image files. It delivers content through edge locations and speed up response times in web applications. The user request, is smartly redirected to the right edge location and the requested content, is returned as son as possible.

Regarding implementation steps:

In the console search bar, search for CloudFront and click Create CloudFront distribution

Select the Origin domain where the CloudFront will cache all the static files and leave all the configurations as default. Here, we should chose the resource that we would like to share.

Click on Allowed HTTP methods and select GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE to allow the application use POST to insert the data inside the DynamoDB

On the Settings, leave it as Use all edge locations to archive best performance.

Click Create Distribution and your CloudFront distribution will be created.

After creation, we will see, our CloudFront instance as enabled. This means that we are able to test and start using our application with CloudFront to help on performance.
To test, we should use the new URL, generated during CloudFront instantiation.

Copy the URL and paste into a browser to see if the application will come up

Conclusion:

CloudFront speeds up the distribution of your content by routing each user request through the AWS backbone network to the edge location that can best serve your content. This is basically a smart way of routing to match customer needs. Typically, this is a CloudFront edge server that provides the fastest delivery to the viewer. This solution is an amazing approach to follow when we want or need to offer slow response time to our customers.

Used AWS Resources:

CloudFront

Reminder: Terminate, stop or destroy all the resources when you are done to avoid being charged for using AWS services beyond the free capacity.

--

--