In this blog, we’ll learn what is CloudFront with its working Demo. So, let’s get started.
Amazon CloudFront is a web service that speeds up the distribution of our static and dynamic web content, such as .html, .css, .js, and image files, to our users.
Our content is delivered by CloudFront through a global network of data centers known as edge locations. When a user requests content served by CloudFront, the request is routed to the edge location with the lowest latency (time delay), ensuring that the content is provided as quickly as possible.
Use cases AWS CloudFront
- Accelerate static website content delivery: CloudFront helps us deliver our static content to viewers worldwide faster. We can take advantage of the AWS backbone network and CloudFront edge servers to provide your visitors with a quick, secure, and dependable experience when they visit our website by using it.
- Serve video on demand or live streaming video: CloudFront provides numerous alternatives for streaming pre-recorded content and live events to worldwide viewers.
- Encrypt specific fields throughout system processing: We can protect specific data with field-level encryption, in addition to HTTPS security, so that only selected applications at our origin can see the data.
- Serve private content using Lambda@Edge customizations: we can configure our CloudFront distribution to serve private content from our own custom origin.
Working of CloudFront
- An object, such as an image or an HTML file, is requested by a user who uses our website or service.
- In order to serve the user request, the DNS now redirects the client request to the closest edge location through CloudFront.
- CloudFront searches for the requested cache file at the edge location. After locating the file, CloudFront sends it to the user.
- If the file cannot be located, CloudFront shares the specs with the origin server after checking the requirements.
- The web server sends the files to the CloudFront edge location in response to the request.
- As soon as CloudFront receives the file, it adds it to the edge location and shares it with the client.
- AWS Account
First, we need to Create an S3 bucket.
Create an S3 Bucket and add some files to that bucket.
Now, we have two ways of accessing it we can access it by object URL but this will not work because our bucket is not public, so it will give us access denied. The other way is by using a pre-signed URL but this will also not work.
Now, we want to access it by Cloudfront, for that go into CloudFront service and click on Create Distribution.
Select the appropriate Origin Domain name, as we are doing a demo for Amazon S3 we will choose that. Create an OAI (origin access identity), it is only available if we are using S3 bucket access.
Now for accessing the objects, open the Distribution domain name in another tab.
This object is not served by not Amazon S3 but served directly from a CloudFront edge location. Also, this object is available Globally.
Also if we check our Bucket Policy we are able to find the origin access identity we made and that is connected to our CloudFront distribution and it is allowing us Cloudfront mostly to get the content from the S3 bucket.
In this blog, we have learned what is AWS Cloudfront and how it works with a demo.
To read more about DevOps.