I've been playing with EC2 spot instances, with the ultimate aim of migrating a standard instance hosting a website to a spot instance (yes, I'm well aware this really isn't what spot instances are for, but in this case I'm quite prepared to trade price for availability).
However, I was a little surprised to discover that when the price threshold is crossed, the spot instance is terminated, not stopped, and indeed that it's simply not possible to stop a spot instance, only to terminate it.
So: is there some (recommended) way of getting the instances spawned by spot instance requests to simply associate themselves with a particular EBS volume on creation, so that the full machine state can simply be rolled forward across a series of spot instances ? Or am I fundamentally misunderstanding what spot instances are all about ?
Firstly, allow me to clarify a few points. As you pointed out, spot instances are not meant to be run 24/7 - they are intended to provide extra compute capacity for a short time-span at a lower cost. Essentially, they are intended for tasks that can be broken into small pieces - so a terminated instance will not have a significant impact on the overall task.
That said, I have previously run an instance using the spot request model - its usual uptime was about 3 months - and I would typically overbid by about 15x the average market price. While this used to be a reasonably cost effective approach, I found that as more people employed the same technique, the price volatility increased to the point that it was no longer advantageous over a reserved instance.
The average spot price tends to hover around the hourly cost of a medium utilization reserved instance. Doing the math based on the current spot prices vs heavy utilization instances, you get the following:
It is evident that in many cases, the 3 year heavy utilization reserved instance works out to less than the current spot price (which is subject to volatility). From my experience, the actual average spot price tends to be at least 50% higher than the baseline market value, since significant spikes are not uncommon.
Now, to actually try and answer your question:
You are correct that spot instances cannot be stopped - in some ways that does agree with the entire premise behind spot instances. Traditionally, an instance will create the EBS volume(s) it is using from snapshots, but it is possible to script the process of attaching an EBS volume. I used to use this script to setup 2 EBS volumes in a RAID0 (I am pretty sure I modified it from some script I found, but I can't find the original at the moment):
This was for CentOS, but I imagine it would be easy enough to adapt to most other Linuxes. Change the Java version and remove the RAID attributes (and change the mount point) and you will be good to go. This would then be setup as an init script to run when the instance starts. An alternate way of accomplishing this would be to pass the EBS volume IDs as instance user-data, which would allow for a lot more flexibility.
It should be noted that this, of course, will not work for the root EBS volume - this setup presumes a mostly fixed root volume, with data kept on a separate mount-point. You can always set the EBS root volume from
ec2-request-spot-instances
using the--block-device-mapping
parameter.What you're looking for can be accomplished through use of their API, I don't think it's possible to use Amazon-supplied automation to do it. You have to write it yourself. It is entirely possible to write a script to create a new spot instance, and associate a specific EBS volume to it.
What you won't be able to do is migrate the full machine-state, you'll still incur outages to spin up new spot instances.
Check out https://github.com/atramos/ec2-spotter
From the README: