CDN on top of your website to increase your core web vitals
Curious software engineer
Search for a command to run...
Curious software engineer
No comments yet. Be the first to comment.
In this series, I will treat subjects related to software development, software engineering, and related career.
If you are going to work on software using Bitcoin or Liquid, there are several concepts you need to be familiar with. This article aims at developers and is based on a presentation I held for the Pixelmatic team. Disclaimer: this is an introductio...
It’s the summer holidays, after all. So I wanted to spent some time with my 7 years old daughter to teach her programming. ⌨️ I spent some time before discussing with her some of the basics concept verbally: the different parts of a computer, and bas...

This article is a follow up on my previous one introducing the concept of SE Spectrum: https://sonny.alvesdi.as/a-better-way-to-discuss Existing solutions For long, the easiest way to run a spectrum was to use visual drawing or diagram tools like ...

Introduction to SE Spectrum

One of the greatest tool available on GitHub is Dependabot. For those not familiar with it, in short it's a bot reviewing your list of dependencies and proposing PRs to update them. https://docs.github.com/en/code-security/getting-started/dependabot-...

Photo by Harli Marten on Unsplash As long as I remember I have always been interested by skepticism. And I think one element that really resonated with me has been that conference talk by Phil Plait: https://www.youtube.com/watch?v=FrFRbGjUtJk 15 ...

This is a long title, but it is on the point.
I am going to show you how to set up AWS Cloudfront, the CDN solution of Amazon, in front of your AWS website.
The solution works if your website is hosted on a single server or if you have multiple instances behind a load balancer. In the case you host your website in a Kubernetes cluster, I don't have a solution at the moment, but feel free to leave your solution in the comments.
Because you will take profit of the very distributed CDN network of AWS! That means your website will be faster and available to a bigger audience. That relies on the good connectivity that AWS maintains inside its internal network.
It means for example instead of serving your website from a central location: a server or a load balancer located in Singapore to a Canadian visitor. You will serve your website from the closest point in the CDN of AWS in Canada.
And why that works? Because of the internal AWS network which is a lot more optimized than the regular internet. Using the regular internet routing to reach out to a website on the other side of the planet would never be as optimized. Internet neutrality won't favor your communication, and your Canadian ISP does not control routing up to Singapore.
On top of that, increasing performances means increasing your core web vitals and your SEO!
First, let's set up the CDN.
Create distribution
Enter your origin
If you have a unique server, use the Public IPv4 DNS
If you use a load balancer, use the DNS name
In the section Default cache behavior,
I suggest you set Redirect HTTP to HTTPS,
(Optional) Set Allowed HTTP methods to GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE if your website have interactions and forms,
Check Cache policy and origin request policy, select CachingDisabled as Cache policy (because your website is dynamic so you don't want to cache), and select AllViewer as Origin request policy (this will allow cookies and query parameters to be transferred to your website origin).
In the section Settings
Check Use all edge locations (best performance)
Click on Add item in Alternate domain name (CNAME) to add your domain name
If you want to have your root domain and www subdomain behind the CDN do it twice
Select or request a certificate for the domain you entered previously
Security policy Click on Create distribution
Second, update your DNS record. Once your distribution is ready copy the Distribution domain name of it, it should start by d. Then update the domain you entered at step 5b.
And voilà.
If you encounter any issues implementing it, leave comments. If you are using Kubernetes and you found a solution to do that, let me know I am curious about it.