In this article, we will look into AWS content delivery network service i.e. AWS CloudFront. We will start it by understanding what is CloudFront service and its benefits. Later, we will discuss how to practically implement this setup in your environment and its use cases and finish it off with the conclusion.
What is AWS CloudFront?
Amazon CloudFront is a fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.
In a simple term, we can say AWS CloudFront is a data/content caching technology that resides at the defined edge locations. So, what is edge location? An edge location is the nearest point to the consumer(user) who is consuming the AWS service. In these locations, the server is not present but AWS CloudFront is set up in which data is cached and will be sent to the user from that nearest edge location instead of picking it from the original location thus speeding up the transfer rate.
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.
AWS CloudFront distribution supports two delivery methods one is Web distribution and the other is RTMP distribution.
When to use Web distribution? Choose Web distribution if you are looking to speed up the distribution of static and dynamic content such as html, css, php, and graphic files. Distribute media files using HTTP or HTTPS. Here, you store your files in an origin- either in an S3 bucket or a Web server.
When to choose RTMP (Real Time Messaging Protocol)? Choose RTMP if you want to speed up the distribution of your streaming media files. An RTMP distribution allows an end-user to begin playing media files before the file has finished downloading from a CloudFront edge location.
Start serving your dynamic content through AWS CloudFront distribution by setting up Elastic Load Balancer for your EC2 instances which contains the dynamic data. When you set up a CloudFront distribution your data will be sent to an edge location using CloudFront’s private network and cached at the location avoiding data transmission via the internet.
Benefits of AWS CloudFront:
- Global Scaled Network for Fast Content Delivery: The CloudFront network has 225+ points of presence (PoPs) that are interconnected via the AWS backbone delivering ultra-low latency performance and high availability to your end-users.
- Security at the edge: All your CloudFront distributions are defended by default against the most frequently occurring network and transport layer DDoS attacks that target your websites or applications with AWS Shield Standard. To defend against more complex attacks, you can add a flexible, layered security perimeter by integrating CloudFront with AWS Shield Advanced and AWS Web Application Firewall (WAF).
- Highly programmable and Secure edge computing: CloudFront allows you to run your own code allowing you to personalize content and respond to your end-users with improved latency.
- Deep integration with AWS: Amazon CloudFront is integrated with AWS services such as Amazon S3, Amazon EC2, Elastic Load Balancing, Amazon Route 53, and AWS Elemental Media Services for easy set-up.
- Cost-Effective: Amazon CloudFront offers cost-effective content delivery globally. Integrated with AWS, there are no transfer fees for origin fetches from any AWS origin and AWS Certificate Manager (ACM) offers custom TLS certificates, at no charge.
How to setup CloudFront distribution for your static website?
Before setting up this service make sure you are aware of launching an S3 bucket by referring to our previous blog https://www.easydeploy.io/blog/aws-simple-storage-service-s3/
Upload this predefined HTML contents to your S3 bucket and make it public. Enable static website and look at the network time it takes for data transmission before setting up CloudFront.
Now, lets see the improved performance once we set up CloudFront.
- Search for CloudFront and Click on it.
- Now Click on Create Distribution and click on Get Started.
- Here under Origin Domain Name paste the bucket website endpoint.
- Here you shall see that your Distribution is successfully created.
- Test the distribution by clicking on the ID to open the CloudFront Distribution.
- Copy the Distribution domain name under General tab and paste the Distribution domain name in the browser and index.html page will be displayed.
- Now analyze the network latency of accessing this object.
Press Ctrl+Shift+I to open the inspection tab a select Network a under Time you can see your latency of your page. Here you see that using the Amazon CloudFront, our website is accessible within a low network latency as compared to before that we access from Bucket website endpoint.
Some of the AWS CloudFront use cases are Website Delivery and Security Dynamic Content & API Acceleration, Live & On-demand Video Streaming, Software Distribution, Game Delivery and IoT OTA.
Lambda@Edge is a feature of Amazon CloudFront that lets you run code closer to users of your application, which improves performance and reduces latency. With Lambda@Edge, you don’t have to provision or manage infrastructure in multiple locations around the world. You pay only for the compute time you consume – there is no charge when your code is not running. Just upload your code to AWS Lambda, which takes care of everything required to run and scale your code with high availability at an AWS location closest to your end user.
Read the real-world use cases where AWS CloudFront usage has tremendously improved data transmission and live streaming performance in different technology platforms.
https://aws.amazon.com/cloudfront/?nc=sn&loc=0
Conclusion
Implement AWS CloudFront in front of your load balancer so the data cached at CloudFront level will be transferred at a faster rate. It allows you to distribute your HTML, css, PHP and other real time content at increased pace.