Table of contents of the article:
CloudFront is a Content Delivery Network (CDN) owned by AWS. CDNs are primarily used for caching, and many customers also use the AWS CloudFront CDN as a security layer or to handle network spikes. With AWS CloudFront CDN, when a user requests a web page or image, the request is routed to one of Amazon's 225+ edge servers . If the edge server already has the resource cached, it is served to the client. If the resource is not on the edge server, it makes a request to a larger edge server called the regional edge cache; if one isn't present, the request goes to an origin server hosting your application. The edge server then saves a copy of the response locally so it can handle the next request without disrupting the origin server. This reduces the load on the origin server, helping you keep the instance hosting your application small, and can reduce client latency by moving commonly requested resources closer to the requester. This is great for latency and user experience, but how does it impact costs?
This CloudFront guide will walk you through the following:
- AWS CloudFront Pricing
- Factors that Determine the Cost of Amazon CloudFront
- Ways to Reduce CloudFront Costs
AWS CloudFront Pricing
AWS CloudFront pricing starts with a very simple pricing model: you're charged per GB transferred to the internet and per HTTP request. There are also many optional features, such as encryption, logging, Origin Shield, file invalidation, and edge server Lambda invocations, which may also incur additional CloudFront charges.
CloudFront Cost and AWS Data Transfer Cost
AWS CloudFront charges per GB transferred from any CloudFront edge server to the internet . Once you start transferring more than 40 TB of data, you're charged less per GB, and the cost continues to decrease as you transfer more data until you reach 5 PB. Like most AWS services, these charges vary by region. The initial fee for serving data in the cheapest regions (the US, Mexico, Canada, Europe, and Israel) is $0,085 per GB, and this cost doubles to $0,170 when serving data in the most expensive region (India). You're also charged for requests that send data to your origin application, such as WebSocket connections, or data attached to PUT requests from a client. Because CloudFront is inherently global, the region you're charged for isn't determined by where your application resides, but by where requests to your application originate. You can manage these costs by setting a price class on your CloudFront distribution that excludes certain regions from your edge server network.
You can get a discount on Amazon CloudFront pricing by committing to a regular level of usage (typically at least 10 TB transferred per month for a one-year commitment). Unlike many other services, these CloudFront “Reserved Instance” pricing isn't published, but if your organization can reasonably commit to transferring that much data for a long period of time, it could reduce your costs, so contact AWS and ask. You can also get a 30% discount by signing up for the CloudFront Security Savings Bundle . You must commit to spending a specific amount on CloudFront services each month for at least a year, and it's a great deal if you're also considering using Amazon Web Application Firewall (WAF) because 10% of the commitment value is earned as WAF credit.
CloudFront Request Costs
Another factor in AWS CloudFront pricing is that you pay per 10.000 HTTP requests, and you'll pay a premium of approximately 25% to handle HTTPS requests. These CloudFront costs also vary based on the region where the request originates, but the price difference is less dramatic than for data transfer, ranging from a 100% premium for data transfer to the most expensive regions to a 10% premium for handling requests from these regions.
Other CloudFront Costs
Origin Shield is an additional caching layer that operates in (and is priced based on) the Availability Zone of your origin server. All requests to your origin server pass through this single caching layer, so users accessing different edge servers in different locations can receive the same cached content, and applications running multiple CDNs have access to a unified caching layer. This service is charged at the same rate as HTTP requests, adding to the cost of any requests that bypass an edge server. CloudFront also allows you to encrypt specific fields so only applications with access to the decryption key can see sensitive data. This service costs $0,02 for every 10.000 encrypted requests (in addition to the cost of HTTPS requests). You can generate and monitor real-time logs for $0,01 for every 1.000.000 log lines written. Finally, you can provide custom SSL certificates and domain names for your CloudFront distributions for $600 per month.
How to Reduce Your AWS CloudFront Costs
Now that you understand Amazon CloudFront pricing and the many cost factors that contribute to its use, there are several common and practical ways to reduce CloudFront costs. Below, we'll discuss ways to reduce S3 and EC2 costs with CloudFront, the best way to configure CloudFront, and how to increase your cache hit rate to reduce costs.
Reduce AWS S3 and EC2 Costs with CloudFront
One of the most common uses of CloudFront is to deliver web and media content stored in an S3 bucket or EC2 instance to customers around the world. With low data volumes, the cost of using S3 is actually lower because you receive the first GB transferred for free each month, but as soon as you start increasing your usage, the lower cost per GB of serving data from CloudFront kicks in. In an economically viable region like eastern Ohio in the United States, that inflection point is 18 GB.
Once the amount of data transferred over the Internet increases, the price gap for data transfer costs starts to widen. Once you start transferring terabytes of data, the distance between publishing content from an origin like S3 and using CloudFront for content delivery increases dramatically.
It is important to realize that CloudFront has a special status in the AWS universe. Normally, you are charged for data transferred between Availability Zones. However, the data transferred from AWS services to CloudFront servers does not cost a dime. If you're transferring a very small amount of data over the internet, it's cheaper not to use CloudFront, but if you're transferring data between zones or dealing with higher data transfer costs, CloudFront will almost always save you money. This special status also makes it convenient to always associate CloudFront with hosting the origin server on the AWS network. If you host your origin server yourself or use a different provider, those savings on data transfer vanish and you have to pay to transfer the data to CloudFront, which means that every time an item is not in the cache, you pay twice,
Comparing the cost of handling HTTP requests between S3 and CloudFront is less straightforward. If your application only provides GET results, handling requests from an S3 bucket is significantly cheaper. In the U.S. Eastern Ohio, you'll pay $ 0,004 for 10.000 requests made directly versus an S3 bucket, but you'll pay at least $ 0,0075 to fulfill requests from CloudFront, which makes it nearly 90% more expensive. This calculation is reversed once you start mixing POST requests. The price does not change based on the request type for CloudFront, but increases by more than 100% for S3 buckets, you will pay $ 0,05 to serve 10.000 POST requests, so CloudFront becomes the best offer, offering 85 discount % on this type of request.
For most applications, data transfer costs and instance size savings will significantly overshadow the cost of processing requests, so this difference is rarely significant, but if much of the cost for the CloudFront application is caused by a lot of small file requests and you can guarantee that those requests will mostly GET and consider skipping CloudFront. Regarding the requests, you should also consider how necessary the use of HTTPS is for your application. Handling HTTPS requests adds about 25% to request costs, so if you're not receiving sensitive data, using a simple HTTP can save you a lot of tweaking.
Configuring Amazon CloudFront to Reduce Costs
One of the best ways to reduce requests to any web server is to cache the content in the client's browser. This basic idea applies twice when using CloudFront, as CloudFront adds a second layer of caching, files are also cached on edge servers. By default, all files served by the CloudFront Edge Server expire after 24 hours, which is too low for many types of content. You can increase the value of your CloudFront network by appropriately caching objects, especially those that you are sure will not change for a while. You can set how long both the client and edge server cache objects by setting the Cache-ControlHTTP header on the origin server. You can also instruct your edge servers to implement their own caching policies by setting the values Time To Live (TTL). when you create or update your CloudFront distribution. Keep in mind that Edge Server caching is important to plan and implement carefully because if you want to invalidate files before they expire, you can invalidate 1.000 paths for free every month, but you will pay $ 0,005 for invalid path after this limit.
AWS CloudFront cache hit rate increased
One of the primary goals of CloudFront CDN is to prevent origin server flooding by allowing edge servers to efficiently respond to client requests. This functionality is compromised if most clients end up requesting content that isn't cached. The ratio of requests handled by the edge server to the number of requests arriving at the origin server is called the cache hit ratio. You can improve this ratio by understanding how the cache key works . When a client requests a resource, CloudFront generates a cache key (by default, this uses the distribution's domain and the path to the requested object, but you can change those settings). CloudFront then stores the cache key and uses it to fulfill future matching requests. To increase your hit ratio, consolidate your application views to resolve to a single cache key and avoid adding data that could cause two requests with the same results to generate different cache keys, such as creating two URLs pointing to the same resource.
Compression to reduce Amazon CloudFront costs
CloudFront can be configured to automatically compress certain file types. CloudFront compression will result in faster load times for clients and reduce costs because edge servers will transfer smaller amounts of data to clients. In addition to using default compression, compress assets as they are delivered from your origin server.
AWS CloudFront Free Tier
CloudFront's free tier is one of the most generous in the AWS family; you get 50 GB of outbound data transfer and two million requests each month for one year. If you're not already using CloudFront, the free tier can help you decide whether it can help you scale the instance serving your application or significantly improve the customer experience by decreasing load times.
Conclusion
Amazon CloudFront CDN makes it easy to manage resources from a globally distributed CDN. This can reduce latency, handle peak demand, and reduce the load on your application servers. Leveraging good caching and compression policies and understanding how the cache key works allows CloudFront to perform these tasks effectively, helping you get the most out of the service. If you need help monitoring and reducing costs for your AWS services , remember you can always contact Managed Server Srl for assistance.

