Table of contents
Amazon CloudFront is AWS's Content Delivery Network (CDN) service. A basic setup of CloudFront isn't hard to achieve, however, the pricing structure can be confusing and difficult to predict. This article is aimed at explaining the various aspects of AWS CloudFront pricing, and how to spend less money on it.
What Is Amazon CloudFront?
Amazon CloudFront is a global Content Delivery Network (CDN) service that safely delivers data, applications, videos, and APIs to users worldwide at high speed and with low latency. The service integrates seamlessly with the extensive infrastructure of AWS, such as AWS Shield for DDoS mitigation, Amazon Simple Storage Service (Amazon S3), Amazon Route 53, and Elastic Load Balancing.
CloudFront operates via a network of data centers called edge locations that are located around the world. These edge locations help deliver content to users in the quickest way possible, thereby reducing latency and ensuring an efficient and reliable service.
CloudFront supports HTTP/2 and IPv6, offers field-level encryption, and integrates with AWS WAF (Web Application Firewall), AWS Shield, and AWS Certificate Manager. These features allow developers to create and manage content delivery efficiently and easily.
How does Amazon CloudFront deliver content?
Amazon CloudFront delivers content through its globally spread network of edge locations. When an end-user makes a request for content that is being served through CloudFront, the request is automatically routed to the edge location that can best serve the user's request. This is typically the edge location that provides the lowest latency.
The process by which CloudFront delivers content to the end-user can be broken down into a series of steps. Initially, when the end-user makes a request for content (like an image or a video), CloudFront routes the request to the edge location that can best serve the user's request. This is decided based on the proximity of the edge locations to the user, with the nearest one usually being chosen.
If the requested content is already in the edge location (cached from a previous request), CloudFront delivers the content directly to the user. If the requested content is not in the edge location, CloudFront forwards the request to the origin server (which can be an Amazon S3 bucket, an HTTP server, or a MediaPackage channel). The origin server then sends the content back to the CloudFront edge location, which in turn delivers the content to the end-user.
Once the content has been fetched from the origin server, CloudFront caches the content at the edge location, making it readily available for any subsequent requests. This is done so that for any future requests for the same content, CloudFront does not need to fetch the content from the origin server again. Instead, it can deliver the content directly from the edge location, reducing latency and improving the user's experience.
The time for which the content stays in the cache of the edge location is controlled by the cache control headers or by the CloudFront caching settings. Once the content is removed from the cache, any future request for the content would again need to be fetched from the origin server.
Master AWS with Real Solutions and Best Practices. Subscribe to the free newsletter Simple AWS. 3000 engineers and tech experts already have.
How much does CloudFront cost?
Is CloudFront expensive? Not really. CloudFront can get expensive, but it's nearly always less expensive than delivering the same content without using CloudFront. The primary factors that contribute to CloudFront costs are the amount of data transferred out to the internet and the number of HTTP or HTTPS requests made.
To give a basic understanding of CloudFront's pricing structure, the costs are divided into three components:
Data Transfer Out to Internet: This is the cost associated with the delivery of content from CloudFront to your users. The cost depends on the region from which the content is being served and the amount of data transferred.
HTTP/HTTPS Requests: CloudFront also charges for the number of requests made by your users. The charges differ based on the type of request (HTTP or HTTPS) and the region from which the requests are served.
Data Transfer Out to Origin: If your origin server is not an AWS service, CloudFront will charge for the data transferred from the CloudFront edge location back to your origin server.
Keep in mind the first 1 TB of data transfer out per month and the first 10,000,000 HTTP or HTTPS Requests per month are free.
CloudFront Price Classes
Pricing varies by geographic region, so the location of your users also impacts your costs. The global nature of CloudFront’s network of edge locations allows the service to maintain high availability and performance, but data transfer rates differ based on whether content is being delivered from the United States, Europe, Asia, Australia, South America, or Africa. Note that this doesn't exactly depend on where the users are actually located, but rather on the edge location from which the content is served. For a better user experience, content should be served from edge locations near the user, but this can increase price.
With CloudFront, you don't get to choose directly which regions to enable or not. Instead, you choose between three different price classes, and the regions that are enabled depend on that.
These are the regions enabled for each price class:
|North America (United States, Mexico, Canada)||Europe and Israel||South Africa, Kenya, and the Middle East||South America||Japan||Australia and New Zealand||Hong Kong, Indonesia, the Philippines, Singapore, South Korea, Taiwan, and Thailand||India|
|Price Class All||Yes||Yes||Yes||Yes||Yes||Yes||Yes||Yes|
|Price Class 200||Yes||Yes||Yes||No||Yes||No||Yes||Yes|
|Price Class 100||Yes||Yes||No||No||No||No||No||No|
CloudFront Price Class 100 will be the cheapest, including only North America, Europe and Israel. Price Class 200 includes all regions except South America and Australia and New Zealand, which are the most expensive. Price Class All includes all regions.
Keep in mind that the price doesn't depend on the Price Class that you choose. It depends on what regions are used to serve the traffic. If you select Price Class All and have 10 users from South America and 10 from the US, you'll be paying more than if you selected Price Class 100. However, with Price Class 100 the users in South America would be served from the nearest region that's enabled, North America in this case, and would have a worse user experience.
CloudFront Pricing Example
To illustrate how AWS CloudFront pricing works, let’s consider an example. Suppose you have an application hosted in the US East (N. Virginia) region, and you have users all around the world. You use CloudFront to deliver 150 GB of data and handle 300,000 HTTPS requests in one month. Keep in mind that the requests are HTTPS, which are priced slightly higher than HTTP requests.
Keep in mind the first 1 TB of data transfer out per month and the first 10,000,000 HTTP or HTTPS Requests per month are free. We're going to exclude these from our calculations, to better understand how CloudFront is priced beyond the free tier.
For the US, Canada, Mexico, Europe and Israel, AWS charges $0.085 per GB for the first 10 TB / month of data transfer out, and $0.0100 per 10,000 HTTPS request. So, your data transfer cost would be 150 GB x $0.085/GB = $12.75. The HTTPS requests cost would be 300,000 x $0.0100/10,000 = $0.30. So, the total cost for CloudFront would be $13.05.
For South America, the rates differ slightly. For the first 10 TB per month, AWS charges $0.110 per GB for data transfer out, and the HTTPS requests are charged at $0.0220 per 10,000 HTTPS requests. So, suppose we deliver an additional 50 GB of data in South America, with 100,000 HTTPS requests. Your data transfer costs would be 50 GB x $0.110/GB = $5.5, and the HTTPS requests costs would be 100,000 x $0.0220/10,000 = $0.22, totaling $5.72 for South America. The total cost for all of our regions would be $18.77.
This is a simplified example, and actual costs can be affected by other factors such as the price for invalidation requests (requests to remove an object from CloudFront cache before the set expiration time), dedicated IP custom SSL, and field-level encryption requests.
You can view the entire calculation in this AWS Pricing Calculator estimate.
Additional Costs for CloudFront Integrations
While CloudFront itself is cost-effective, integrating it with other AWS services may result in additional charges. For instance, if you store your files in an Amazon S3 bucket, you'll incur S3 storage costs. Similarly, if you're using AWS Shield for DDoS protection or Amazon Route 53 for DNS, you'll be billed for those services as well.
Remember that while CloudFront does charge for data transfer to the viewer, it does not charge for data transfer from origin servers like Amazon S3, Elastic Load Balancing, or EC2 to CloudFront. You also won’t be charged for viewer requests to your website.
Amazon CloudFront Pricing Tips and Tricks
There are several strategies you can employ to optimize your CloudFront costs. Here are a few tips and tricks:
Use the AWS Free Tier: The first 1 TB of data transfer out per month and the first 10,000,000 HTTP or HTTPS Requests per month are free, forever. This means even accounts older than 12 months enjoy this free tier.
Price Classes: You can reduce the cost of delivery by choosing a price class for your CloudFront distribution that includes only the regions that your main users are in. This allows you to exclude more expensive regions where you may not have users. If a user requests the content from a region you haven't configured in CloudFront, they'll still be able to get the content, just with increased latency. For example, if you only configure North America, a user in South America will have their request sent to the edge locations in Mexico.
Caching Optimization: Fine-tune your CloudFront cache settings to maximize the caching of your content at edge locations. This reduces the need to fetch data from the origin, which can significantly cut down data transfer costs.
Data Compression: CloudFront can automatically compress certain files at edge locations. This can reduce the size of data that CloudFront needs to transfer, which in turn can reduce your cost.
CloudFront Savings Bundle: For those with predictable high-volume traffic patterns, committing to a certain level of usage by purchasing a CloudFront Savings Bundle will result in a reduction of up to 30% of your CloudFront costs.
Amazon CloudFront Use Cases
There are several common use cases for Amazon CloudFront, including static asset caching and live streaming. These use cases highlight how businesses leverage the service to enhance their operations and serve their users more effectively.
Static Asset Caching
CloudFront is also used for streaming live events such as sports, gaming tournaments, and concerts. The AWS Elemental MediaPackage integrates seamlessly with CloudFront for a scalable and cost-effective live streaming solution. Content providers can deliver live video with low latency to a global audience, providing an excellent viewing experience.
Master AWS with Real Solutions and Best Practices.
Join over 3000 devs, tech leads, and experts learning real AWS solutions with the Simple AWS newsletter.
Analyze real-world scenarios
Learn the why behind every solution
Get best practices to scale and secure them
Simple AWS is free. Start mastering AWS!
Did you find this article valuable?
Support Guillermo Ojeda by becoming a sponsor. Any amount is appreciated!