How to Save Money When Hosting on AWS

How to Save Money When Hosting on AWS

by Alex Hyett | 5 min read

When I started my first startup GrowRecruit I went with the recommended setup. However, I soon found that what is recommended is actually quite costly for a bootstrapped startup.

If your product is still at the MVP stage (Minimum Viable Product) and you haven’t got customers yet, you want to avoid spending large amounts on AWS hosting.

My initial setup consisted of the following:

  • VPC with Public and Private Subnet and NAT Gateway
  • 2 t2.small instances RDS database cluster (one read, one write),
  • 2 t2.micro instances, one for WordPress the other for my API
  • 2 S3 buckets
  • Route 53

This is a fairly small setup for bootstrapped SaaS, I would have liked to go with a smaller RDS instance, however, t2.small was the smallest available that offered encryption.

The total cost per month $146.95! Not exactly the cheap bootstrap price I was looking for.

Step 1: Cut unused services

To start working out what you need to cut, you need to look at your bill. This is what mine looked like:

AWS Charges

As you can see the expenditure is mostly in 3 areas: Elastic Compute Cloud, Relational Database Service and VAT.

Elastic Compute Cloud

I have 2 EC2 Instances both t2.micro, one for my API the other for a WordPress installation which I use for my marketing site.

With one of these instances covered under Amazon’s Free Tier, the cost for running these instances is $3.65. This would have been $9.23 but I opted for a reserved instance. I will cover what reserved instances are below.

So where on earth was this other $49.42 coming from?

  • NAT Gateway - $35.72
  • Elastic Load Balancer - $13.68
  • EBS - $0.02

So I was spending $35.72 on a NAT Gateway. So what is a NAT Gateway and do you need it?

NAT Gateway

The purpose of a NAT Gateway is to allow instances in your private subnet to access the internet but prevent the internet from accessing those instances.

In my case, the only thing in my Private Subnet was my database and that didn’t need internet access. So I got rid of my NAT Gateway and managed to save myself $35 a month.

If you do need a NAT Gateway you can set up a NAT Instance which may work out cheaper for you.

Elastic Load Balancer

The second highest expense was the Elastic Load Balancer (ELB). Now I am running my API using Elastic Beanstalk and the ELB is required for SSL on my API endpoint. So there was no getting rid of that one.

Step 2: Commit to payment or pick your instance type

AWS has 2 ways you can save money, reserved instances and spot instances.

Reserved Instances

Reserved instances are a great way to save money if you are planning on keeping your servers long term.

Amazon has 3 different ways that you can reserve an instance.

  • All Upfront - This obviously has the highest upfront cost but you save the most in the long run.
  • Partial Upfront - In this case, you pay a portion upfront and then pay a discounted hourly rate for the rest of the term.
  • No Upfront - As the name suggests you don’t pay anything upfront but you do commit yourself to a fixed monthly outgoing each month for the duration of the term.

In the case of my EC2 instance, I went with the Partial Upfront payment which cost me $43 upfront which brought my monthly cost down to the $3.65 you see above.

I did the same with my RDS instances but this time I chose the No Upfront which brought my database costs down from $68.30 to around $53. However, I wouldn’t recommend this option as it ties you into a contract for at least a year.

Spot Instances

The other option you have here to bring your cost down is spot instances. With spot instances, you can save significant amounts on your EC2 instances but it comes at the cost of reliability.

With Spot Instances, you are getting spare computing power which would otherwise go to waste. When you set up a spot instance you can specify the maximum amount you are willing to spend and the type of instances you want to have.

Spot instances are a great option for fault tolerant background processes that can afford not to run occasionally.

They are also a great option for test environments, although just make sure QA know to take this into account when they are testing your software.

Step 3: Move to cheaper options

If you have run out of options with your current configuration it may be worth considering AWS’s cheaper configurations.

S3 Storage

Amazon S3 storage is dirt cheap. I am currently running 3 blogs (including this one) and the frontend of GrowRecruit for $0.05 a month.

To save even more money I created a static copy of my Wordpress blog running on my EC2 instance using the WP Static Site Generator Plugin and hosted it in an S3 bucket with CloudFront on top.

The Wordpress theme I was using was overly bloated and took an age to load. I switched this out for a super fast Gatsby blog, like this one.

Go Serverless

You can save a lot of money by going serverless if your application isn’t being used heavily. Amazon offers a range of serverless technologies including Aurora Serverless and Lambda Functions.

If I was going to rewrite my startup I would definitely consider using serverless technologies. Just make sure you keep an eye on the costs. If you start getting a lot of traffic you might want to consider going the instance route.

Conclusion

With the above tweaks, I managed to nearly half my AWS costs and now pay around $75 a month.

If I was using Aurora Serverless however it would be a small fraction of that.

Unfortunately, Aurora Serverless wasn’t out yet when I set up GrowRecruit and I am now tied into a year-long contract! Lesson learned the hard way on that one.


ALSO ON ALEXHYETT.COM

Hosting n8n for Free with Railway

Hosting n8n for Free with Railway

  • 30 January 2023
I have been using n8n for a couple of months now, and it has allowed me to automate so much of my daily workflow. These are some of the…
Using GitHub Actions to Deploy to S3

Using GitHub Actions to Deploy to S3

  • 26 March 2021
Recently I went through the process of setting up Drone CI on my Raspberry Pi. The plan was to use my Raspberry Pi as a build server for…
Getting Started with AWS Step Functions

Getting Started with AWS Step Functions

  • 12 March 2021
I have recently been looking into AWS Step Functions. For those not familiar with them, Step Functions are Amazon’s way of providing a state…
Useful Docker Commands Worth Saving

Useful Docker Commands Worth Saving

  • 12 February 2021
I use docker every day. All the applications I write at work or at home end up in docker containers. Most of the time though, I am only…
Grafana Monitoring on a Raspberry Pi

Grafana Monitoring on a Raspberry Pi

  • 28 January 2021
As you might have seen from my last few posts I have quite a lot running on my Raspberry Pi. I am currently using a Raspberry Pi 2 B which…
How to set up Drone CI on Raspberry Pi (and why you shouldn't)

How to set up Drone CI on Raspberry Pi (and why you shouldn't)

  • 27 January 2021
I wanted to put together my home build server using my Raspberry Pi. After looking at the options I picked Drone CI, it has a nice interface…
Traefik vs Nginx for Reverse Proxy with Docker on a Raspberry Pi

Traefik vs Nginx for Reverse Proxy with Docker on a Raspberry Pi

  • 20 January 2021
I use my Raspberry Pi as my own personal home server. Up until recently, I have been using nginx as a reverse proxy for my docker containers…
Hosting a Secure Static Website on AWS S3 using Terraform (Step By Step Guide)

Hosting a Secure Static Website on AWS S3 using Terraform (Step By Step Guide)

  • 14 January 2021
By the time you finish reading this article, you will know how to get your static websites up and running securely on AWS using Terraform…