Hello!

Continuing the topic of saving money in the clouds, today I will talk about
Spot Instances . Let me remind you that AWS has at least 3 main types of cost optimization:
What is a Spot instance?
This is a regular EC2 or VPC instance, but there are some nuances of work:
- As mentioned earlier, this is a regular instance. Computing and network resources, disk speeds and everything else on machines is the same as regular EC2 instances.
- You set the price you will pay per hour of the instance. You will not pay more.
- An instance can be turned off at any time, for example, if someone has bid more for a slot that you occupy and no others.
- Payment is made for the full hour of the instance. Part of the hour is discarded in favor of the client - down to full hour.
Spot instances use unused EC2 slots to prevent them from being idle.
')
Why use machines that can shut down any minute?
Everything is very simple. It is cheap. If criticality of uptime is not important, then this is the ideal way to work.
Here is a simple usage of using Spot instances. Every night, your application collects pictures that users have uploaded in a day and creates icons from them. Everything is absurdly simple: 50 Medium High-CPU instances go up, look at SQS and in turn process everything in the
uploaded folder in your S3 bucket. Well and put in the processed folder.
They usually cope in 2 hours. It makes no sense to reserve them for such amount of time, even Light Utilization Reservation will not cover expenses. For these 2 hours you will pay for instances
2 * 50 * $ 0.165 =
$ 16.5 per day and
~ $ 511 per month .
You can save on this. You just need to start using Spot Instances. At the time of this writing, the cost of a Spot Medium High-CPU instance is
$ 0.018 . Make a difference between
$ 0.018 and
$ 0.165 . So, we put in the application, on average, 2 times the cost of the spot instance in an hour, so that our bids will not be interrupted. And we get the following calculations:
2 * 50 * $ 0.036 =
$ 3.6 per day and
~ $ 111 per month .
In this scenario, we get
~ 80% savings. The only thing we need to remember is that the instance can be put out. Correct processing of files is what should be embedded in your software.
How to order a spot instance?
In the Instances menu in the console, we find Spot Requests and create a new request. We choose the prepared AMI with our software. Next, we drive in the parameters of the spot request:

Well and further as usual.
More about spot instances can be found on the official
page . There are a lot of pictures and all sorts of explanations why this is all cool.
Finally, a small questionnaire on the topic.