Voiced by Amazon Polly |
Introduction
Amazon CloudFront is a globally distributed content delivery network with over 150 edge locations worldwide. The service helps you cache the data at edge locations served when requested by a nearby end user. You can cache extensions like jpg, png, js, and even videos to reduce stress on your origin servers.
We have different types of cache policies used to control the cache behavior for static objects, we will talk about the behaviors, policies, and functions in more detail.
Customized Cloud Solutions to Drive your Business Success
- Cloud Migration
- Devops
- AIML & IoT
Steps to Cache Behavior
If you want to cache a particular extension, follow the below steps:
- Navigate to your distribution and select behaviors.
2. Create a behavior pattern
3. Select viewer protocol policy allowed HTTP method as per the preference and use case
Note: As a best practice, you should keep the Default (*) path behavior as caching disabled and use caching for only the required static extensions.
Cache key policies and origin request policies
AWS recommends having a cache policy and origin request policy to control the cache behavior for the origin requests.
Let’s navigate to policies in the left-hand side pane to view more.
You may link a set of managed cache rules from CloudFront to any cache behaviors offered by your distribution. You don’t have to create or keep up with your cache policy when using a managed cache policy. The controlled policies use settings that are optimized for certain use situations.
A list of managed ache policies are
Custom Cache Policy
TTL: Using a custom policy, you can have custom TTL (Time to live settings). This works with Cache-control to control how long the CloudFront cache remains valid.
Cache key: The key settings define the values that CloudFront includes in the cache key in viewer requests. Possible values include cookies, HTTP headers, and URL query strings. The values you specify for the cache key are automatically included in the origin requests that CloudFront delivers to the origin.
Compression: When the viewer supports it, these options allow CloudFront to request and cache compressed items using the Gzip or Brotli formats.
Custom Origin Policy
The origin is contacted to get the requested item when a viewer request to CloudFront results in a cache miss (the requested object is not cached at the edge location).
Cache policies manage the cache key and are distinct from origin request policies. This division helps you retain a high ratio of cache hits while receiving more information at the origin.
By utilizing the policy, all URL query strings, HTTP headers, and cookies can be included in origin requests, as shown below:
Functions
Using CloudFront Functions for large-scale, latency-sensitive CDN modifications, you can make lightweight JavaScript functions. The CloudFront Functions runtime environment is extremely secure, with startup speeds of less than one millisecond, and scalable instantly to accommodate millions of requests per second. Being a native component of CloudFront, CloudFront Functions enables you to write, test, and deploy your code directly inside of CloudFront.
We will create a function for our distribution that will fetch the client IP from the viewer to the origin as a header
Steps to create a CloudFront function
- Navigate to functions under CloudFront.
2. Create a new function
3. Click on build and paste the function, and we have this function to request a true-client-Ip header from the CloudFront distribution.
4. After adding the function, click on publish to publish the same.
5. Click on add an association to add this function to your distribution.
Now your origin will start receiving the true client IP as a header.
Conclusion
CloudFront is a state of art service provided by AWS, features such as multi-origin, behaviors, cache policies, origin requests policy, and functions make the service configurable and customizable.
You can start using default settings in CloudFront and gradually customize it as required. Take advantage of 150 plus edge locations worldwide, reduce your server usage, and make your front end highly available.
Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.
- Cloud Training
- Customized Training
- Experiential Learning
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.
FAQs
1. Can we view metrics in Amazon CloudFront?
ANS: – Yes, we can view the metrics such as requests, data transfer, error rates, and more.
2. Can we use CloudFront without caching or data?
ANS: – Yes, we can use the service without caching by enabling no caching behavior on the default path pattern.
3. What other services can be integrated with AWS CloudFront?
ANS: – Services such as S3, WAF, Amazon EC2, Elastic Load Balancing, and Amazon Route 53 can be integrated with CloudFront.
WRITTEN BY Akshay Mishra
Comments