Cheap Static Hosting with AWS and Cloudflare
TL;DR Host static content on AWS S3/CloudFront and manage the domain on Cloudflare
I’ve been managing a couple of SPA’s for friends and family members for a few years now. Initially, I used the shared hosting service offered by a variety of Domain/ Hosting providers. It used to work fine, but I always thought why should I pay for shared hosted compute when I only just want to host a static website (without PHP). So I switched to AWS for simple hosting, typical website setup looks like
- S3 Bucket with source code
- CloudFront distribution
- ACM certificates for domain(s) (naked, www)
- Route53 Hosted zone and records
This setup was simple and easy with Terraform and was significantly cheaper than Shared hosting, but the reason it was cheaper because of the free tier especially the First year in AWS. I was again worried about what would happen after the first year/ free tier expires. So I investigated which parts of AWS are costly, and the answer was Route53. The Websites that I maintain have very low to medium traffic every month. As per current AWS pricing main cost of Route53 is
$0.50 per hosted zone / month for the first 25 hosted zones
For each hosted zone I had to pay half a $
. If I could remove this fixed cost It would almost reduce my monthly spending
by 80% for all the websites.
Enter Cloudflare, they are the best solution for DNS management in my opinion, and they offer a free plan which I use for all websites and is enough for my needs. My current setup of the simple static website looks like
- S3 Bucket with source code
- CloudFront distribution
- ACM certificates for domain(s) (naked, www)
- Cloudflare records for ACM validation
- Cloudflare records pointing the domain to CloudFront
Of course, you have to signup for AWS to get AWS Access keys, Cloudflare API token which I have not mentioned here but you can figure that out by simple googling :)