o7planning

How to reduce Amazon Cloudfront Costs?

  1. Objective of the article
  2. How expensive is Amazon Cloudfront?
  3. How to cut usage costs?

1. Objective of the article

I had been using Cloudflare for 3 years. During that time I also learned about many other CDN services in the world. Eventually, I found Amazon Cloudfront, one of the great choices. People also talk a lot about it on different forums. There is no doubt about its quality, but bad news is that it is very expensive. Some people have to pay bills of hundreds of dollars a month for this service, which is petrifying compared to the charge of Cloudflare.
In this article, I'm going to talk about solutions to reduce the cost of transferring data from Cloudfront (Amazon S3) to the Internet,so you can use this service with your peace of mind without worrying about the bill increase.
First of all, please read my following article about Amazon Cloudfront and its relation with Amazon S3:
You can also read an article about the differences between Cloudfront and Cloudflare:
  • Cloudfront vs Cloudflare

2. How expensive is Amazon Cloudfront?

When using CloudflarePro package, you have to pay $20 per website; whereas Amazon Cloudfront does not care how many websites you use. What it only cares is how much data is distributed to the Internet, and this is how they take money out of your pocket.
Before offering a cost-effective solution to using Cloudfront, we need to have an overview of how expensive Cloudfront is. Here I just mention the cost of transferring data to the Internet from two low-cost areas of America or Europe.
Basically when using Cloudfront,you get 1GB free every month. Later, you have to pay about $0.085/1GB, which means you have to pay one dollar just to transfer 11.7GB of data to the Internet.
A page will include HTML and other static data such as Image, Css, Javascript and so on with an average size of roughly 2MB, or sometimes 5MB if your website contains lots of images.
Assuming that each page is 2MB and each user views one page of yours, 11.7GB is only enough to serve 5990 people (And you have to pay $1 to Amazon).
If your website has 20,000 page views every day, it will cost you $3.3, and you must pay $100 each month. It is normal for websites with a lot of traffic to get a bill of 500 dollars or more.
Let's make a comparison with renting one VPS:
  • By renting a VPS at the price of $5/Month, you get 25GB of storage and 1000GB of data transmission for free.
  • By renting a VPS at the price of $20/Month, you get 80GB of storage and 4TB of data transmission for free.
Indeed, using the Amazon Cloudfront service is costly. You can check out the links below for the detailed price list.

3. How to cut usage costs?

In mid-2020, I switched to DigitalOceanVPS service and found out that they have a great storage service called DigitalOcean Spaces. This service has a similar architecture to Amazon S3, and is fully compatible with the Amazon S3 Rest API.
DigitalOcean allows you to create Spaces(s). Each Spaces is like an S3 Bucket of Amazon S3, but more importantly, Spaces already supports CDN.
DigitalOcean Spaces charges are inexpensive. With 5 dollars a month, you are provided with 250GB hard disk drive and permitted to create unlimited Spaces and 1TB free to transfer data to the Internet. If you pass this quota, you will have to pay an additional fee of $0.02/1GB.
As you may know, one page of website includes HTML content and other contents such as Css, Javascript, Image, etc. Assuming that the total size of all is 2MB, in which the HTML content is very small, only about 10KB to 100KB. If you only put HTML data in Amazon S3 and other static data in DigitalOcean Spaces, the amount on your bill will be reduced by at least 20 times.
If you have never used DigitalOcean, click the link below and create a new account. You will get $100 in credit valid within two months.
Gzip?
Amazon Cloudfront supports Gzip to compress static files. When it is enabled, HTML files can be reduced 5 times in size. When a request is sent to Cloudfront,it will return to the browser a Gzip file, the browser will extract this file to get the original HTML content.
Assuming that HTML files with a size of about 100KB are compressed into 20KB, and your website has 20,000 page views a day, Cloudfront will transfer 390MB to the Internet. Cloudfront will transfer 11.5GB to the Internet in one month, which is equivalent to $1 (a staggering amount).
Note: In reality, Amazon Cloudfront charges are a little more complicated. They depend on the geographic location of the server serving the user. However, with the aforementioned solution, your Amazon bills will be significantly cut.
  • Amazon Gzip S3