How to Save Money When Hosting on AWS

Alex Hyett - Nov 5 '20 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player