DEV Community

Cover image for How I saved 90% by switching NATs
Peter Gleeson
Peter Gleeson

Posted on

How I saved 90% by switching NATs

If a service runs in the cloud and no one is around to use it, does it cost any money? If you’re using the default AWS NAT, the answer is yes.

I recently deployed a node websocket server using the SST Service construct. Until this point my stack had been functions and buckets. While I had no users 😢, I also had no costs 🤡.

I’ve been building my solo, bootstrapped, pre-revenue, pre-product-market-fit app for the last few months. Qualifier soup aside, using SST has been great. The dev loop is fast, the defaults are good, and most importantly, I spend my time building my product and not fritzing with infrastructure.

A few days after deploying this service, I noticed a curious “EC2-other” category of cost growing on my AWS console. This ambiguous category quickly became far and away the most expensive thing in my stack.

I did my best to ignore it. Two dollars a day isn’t too bad, you’ve got more important things to do, I told myself. There was something about it that tilted me. Start the day, open up the AWS console, no users, two bucks in the bin. Start the next day, open up the AWS console, no users, two more dollarydoos in the bin. Luckily I am an emotionless deliverer of customer value, with eyes only for converting users and growing revenue.

I lasted one month. I got my December bill and “EC2-other” accounted for 60% of the total cost. I had to know what this was. With Scooby Doo and the crew I jumped into the Cost Explorer and unmasked “EC2-other”… It was “NatGateway-Hours” all along! “NatGatway-hours” is a charge for each hour that your gateway is provisioned and available. When you deploy a Service with SST a managed AWS NAT is included by default.

The villain had been identified, but justice was yet to be served. Rummaging around the SST Discord turned up a number of helpful messages describing run-ins with the same antagonist. This put me onto a wonderfully named project - fck-nat. A line in the README struck a cord:

Overpaying for AWS Managed NAT Gateways? fck-nat

I cludged together some code from Discord messages, gave it a once-over, and deployed it to the cosmos. It worked, or at least nothing was broken. I would have to wait for the next day to see whether I had reduced any costs.

Screenshot of AWS cost graph

The next morning I crested the hill on my AWS console to confetti and the glorious sound of trumpets. Victory! The “NatGatway-Hours” charge was banished, along with the $1.47 cost per day. Replaced by the fck-nat t4g.nano EC2 instance, costing a meager $0.16 per day. That’s a 90% reduction in cost and a 100% increase in satisfaction.

So, if a service runs in the cloud and no one is around to use it, does it cost any money? Well yes, but a lot fcking less with fck-nat.

Now back to finding users.

...

I've put together an example of how to use SST Service and fck-nat together.

If you have any questions or comments, let me know! Thanks for reading.

Top comments (1)

Collapse
 
nateeo profile image
Nathan Hur

What an riveting adventure! 🐴🤠👍