This is the takeaway notes that I have written down from Ryan Kroonenburg’s online training. He is a founder of A Cloud Guru (One of the Best AWS Training provider on the planet!).
Let’s start understanding what is AWS CloudFront service and what we can do with this.
As per AWS documentation,
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 user is routed to the edge location that provides the lowest latency (time delay), so that content is delivered with the best possible performance.
To understand CloudFront, we need to understand different terminologies involved in it.
Content Delivery Network ( CDN)
System of distributed servers that delivers web pages and other static web content to the user based on the Geo-graphic location of the user, the origin of the website and content delivery server.
This is the location where content is cached. This is different from AWS region/Availability Zone (AZ).
- You can do both read and Write into it.
- 50 Edge locations in the world. AWS keeps adding this across geographies.
- Content is cached till TTL (Time to Live).
- You can clear cached objects but you will be charged.
This is the origin of all the files that CDN will distribute. This can be either S3 Bucket, an EC2 instance, Elastic Load Balancer or Route 53.
This is the name that’s given to the CDN which consists of a collection of Edge locations.
When you want to use CloudFront to distribute your content, you create a distribution and choose the configuration settings you want. For example:
- Your content origin—that is, the Amazon S3 bucket, AWS Elemental MediaPackage channel, or HTTP server from which CloudFront gets the files to distribute. You can specify any combination of up to 25 Amazon S3 buckets, channels, and/or HTTP servers as your origins.
- Access—whether you want the files to be available to everyone or restrict access to some users.
- Security—whether you want CloudFront to require users to use HTTPS to access your content.
- Cookie or query-string forwarding—whether you want CloudFront to forward cookies or query strings to your origin.
- Geo-restrictions—whether you want CloudFront to prevent users in selected countries from accessing your content.
- Access logs—whether you want CloudFront to create access logs that show viewer activity.
There are two different types of distribution you can create in AWS
- Web Distribution – Typically use for web applications
- RTMP – distributions stream media files using Adobe Media Server and the Adobe Real-Time Messaging Protocol (RTMP). An RTMP distribution must use an Amazon S3 bucket as the origin.
How does CDN work
When first request is made, it will be routed to edge location. It will check whether the request file is cached at that location and if it doesn’t then it will pull from the original website and will cache it till TTL (time to Live).
When the subsequent requests are made withing TTL, now location have cached copy of content and it will serve quickly.