A Developer's Explanation to Edge Locations in AWS
4 min read
I have a question for you : Have you ever used Cloudfront ? Maybe you've heard about Edge Locations, but you never really understood what it was.
This article is a guide to help you understand what exactly are Edge Locations in AWS, the relation with Cloudfront and how you can benefit from it, to deliver your content with the lowest latency possible.
Edge Location: A site that CloudFront uses to cache copies of your content for faster delivery to users at any location.
In simpler words, Edge locations are data centers spread across the world designed to deliver services with the lowest latency possible. These data centers (located in major cities) are closer to the users, so responses to users requests are way faster.
You can find here a map of the Edge Network.
NB: These data centers are not regular data centers. You cannot deploy your app on the Edge locations, they are just here to cache your content from the main data center in the Region where your application is deployed, to deliver your content faster. Edge locations are only used by Amazon’s managed services.
The main benefit is the fastest content delivery for your users.
For example, I live in Nice, the South of France, and I want to access to a website that is deployed on the region eu-west-1 (Ireland).
My request will be probably longer than another user located in Dublin.
But I'm lucky, because there is an Edge Location in Marseille, which is closer to me. It will catch the website content, so my request will be way faster.
How to use it
As a developer, you don't directly use Edge Locations by clicking somewhere on the console, or declaring it in your infra-as-code (CDK, Terraform, Cloudformation ...).
Requests from your end users will automatically be routed for the best possible performance when you use those services.
However, you can configure some options to decide how your content will be delivered. For example, you can control how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin. For more information about the cache expiration, check the AWS Documentation.
Services using Edge Locations
Cloudfront : Amazon CloudFront is a content delivery network (CDN) that speeds up distribution of your static and dynamic web content, such as .html, .css, .js, and image files, to the users.
This is what happens when a user requests content that you're serving with CloudFront :
- The request is routed to points of presence (POPs = edge location) that provides the lowest latency, so that content is delivered with the best possible performance.
- If the content is already in the edge location with the lowest latency, CloudFront delivers it immediately.
- CloudFront has also regional edge caches, which are located between the origin server and the POPs. If the files are not in the edge location cache, the POPs go to the nearest regional edge cache to fetch the object.
- If the content is not in the regional cache, CloudFront retrieves it from the origin and caches it.
Route 53 : Amazon Route 53 is a cloud Domain Name System (DNS) web service. Route 53 sits in edge locations to route requests to the closest location.
Lambda@Edge: Lambda@Edge is an extension of AWS Lambda. You write and deploy your function in one region (North Virginia), but executes them in AWS locations closer to the viewer. Available since mid-2017, Lambda@Edge is a feature in AWS that introduces the concept of executing code directly on CloudFront’s edge servers.
You can find example functions here.
CloudFront Functions is ideal for for use cases like the following:
- Cache key normalization
- Header manipulation
- URL redirects or rewrites
- Request authorization
You can find more information about this in the Cloudfront functions documentation.
S3 Transfer Acceleration : Amazon S3 Transfer Acceleration is a bucket-level feature that enables fast, easy, and secure transfers of files over long distances between your client and an S3 bucket. Transfer Acceleration takes advantage of the globally distributed edge locations.
You can find more information about this in the S3 documentation.
That's it 🎉
This blog post, should give you an overview of Edge Locations and AWS Services that are using it.
You can also check the AWS Cloudfront documentation to get started and build your first distribution.
If you want to know more about Serverless and AWS follow me on Twitter for more content or check my blog on Hashnode.
See you in the next one ! 🤖