Step-by-Step Guide: Setting Up AWS CloudFront for Lightning-Fast Website Performance ⚡
Unlock lightning-fast content delivery with CloudFront in just 6 simple steps!
What is CloudFront
Amazon CloudFront is a web service that speeds up the 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.
Benefits of AWS CloudFront
- If the content is already in the edge location with the lowest latency, CloudFront delivers it immediately.
- If the content is not in that edge location, CloudFront retrieves it from an origin that you've defined—such as an Amazon S3 bucket, a MediaPackage channel, or an HTTP server (for example, a web server) that you have identified as the source for the definitive version of your content.
- It will cache your content in edge locations and decrease the workload, thus resulting in the high availability of applications.
- It is simple to use and ensures productivity enhancement.
- It provides high security with the ‘Content Privacy’ feature.
- It facilitates GEO targeting services for content delivery to specific end-users.
- It uses HTTP or HTTPS protocols for quick delivery of content.
- It is less expensive, as it only charges for data transfer.
How Does AWS CloudFront Work?
The following steps explain how CloudFront delivers the content:
Step 1
The client accesses a website and requests to download a file (like image file).
Client Access
Step 2
Now, the DNS routes the client request to the nearest edge location through CloudFront to serve the user request.
User requests resource
Step 3
At the edge location, CloudFront looks for its requested cache file. Once the file is found, CloudFront sends the file to the user.
Cache file - CloudFront
Step 4
But, if the file is not found then CloudFront compares the requirements with the specifications and shares it with the respective server.
Web server - CloudFront
Step 5
The web server responds to the request by sending the files back to the CloudFront edge location.
Server sends file in Edge Location
Step 6:
As soon as CloudFront receives the file, it shares it with the client and adds the file to the edge location.
Create Distribution:
- Go to CloudFront distributions and select create a distribution.
CloudFront Distributions in AWS
2. Select your desired s3 origin domain
Choose AWS S3 origin
3. Select viewer protocol policy to redirect HTTP to HTTPS and allowed HTTP methods to GET, HEAD, OPTIONS, PUT, PATCH, and DELETE. Note: We're keeping it public ( you can restrict the distribution access)
CloudFront Asset Redirect
4. Keep cache key and origin requests or you can change them if it is needed.
CloudFront Resource Cache Policy
5. Keep settings as it is or you can change them if it is needed.
Setup HTTP2, Serve from Edge Locations
6. Finally, click create a distribution!
Create Distribution!
Changing S3 URL to Cloudfront domain URL
- In CloudFront distributions, you find all of your distributions and select your desired distribution.
Select Distribution
2. After selecting distribution, you will find details about your distribution and also find the distribution domain name.
Distribution Details
3. Domain name using the style is given below
Mapping domains from S3 to CloudFront
References:
🔖 About the Author
Ankur Datta
dev.ankur.datta@gmail.com
Ankur Datta: self-proclaimed cool dude and tech wiz. He can code circles around most mortals and talk tech jargon with the best of them.