Spot me an EC2 instance

If you’re looking to save money on your AWS bill, consider switching to a Spot instance.

I’ve been running most of my websites on a single Amazon EC2 instance for about 2 years now. It’s been fine: there’s a bit of setup involved but I’ve become more familiar with Linux servers as a result; and if ever I encounter a problem the solution is never more than a single Google away.

The first year on AWS was great: by creating a new account you get some things in your first year for free. A t2.micro instance (1 CPU, 1GB RAM) was part of this free tier, and it comfortably ran 5 of my little Node.js hacks so long as they don’t get too much traffic.

The following year meant that that same server was no longer free. An ‘on-demand’ instance (where pay per hour that it’s in use) costs just over $9 per month, but if you know you’re going to keep it running for a year, you can pay some of the money up front and bring the effective cost down to $6.50 per month. I thought that was a reasonable price, so I paid that for the second year.

Recently at work I learned about Docker and I thought I should try to use it for my projects. Creating a simple build script for each project and deploying them on my server was easy enough, but I often ran into some significant performance problems. In particular, a trivial ‘npm install’ build step took over 20 minutes to complete because the server started running out of memory. One way to fix this would be to upgrade the server to a t2.small (same processor but 2GB RAM) at double the cost. I didn’t really want to give more money to Amazon if I could help it.

That’s when I discovered Spot instances. Spot instances work out much cheaper than On Demand ones but there is some risk. The idea is you ‘bid’ for an instance by saying how much you’re willing to spend per hour. There is a going rate (the price you actually pay no matter what your bid was), but this can fluctuate. If your bid is below the current rate, your instance will be terminated.

The price of certain instance types can rise and fall. If I’d bid $1.50 per hour for this server, it would have been terminated during the middle of August.

A t2.small Spot instance works out at around $5.50 per month. I’m now paying less money for double the RAM in my server! Result!

When setting up a Spot instance, you need to provide an AMI (Amazon Machine Image – a snapshot of an instance), so that when the server starts, so do your applications. It might be a good idea to start an On Demand instance, install your applications to get them running automatically, then create an AMI.

Since Spot instances can terminate without notice (when the rate rises), you might run into a problem if you’re running a website (or 5) on one. I created an AWS Lambda that checks the health of each website, then sends me an email when their state changes. More on that next time.

For more info on the types of EC2 instances and their prices, head over to It’s much easier to understand than Amazon’s documentation!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s