AWS EC2 Spot instances are a great way to get started with Amazon Web Services, but they can be difficult to stop and start. In this article, we’ll show you how to stop and start an AWS EC2 Spot instance using the AWS Management Console and the AWS Command Line Interface. ..
Spot instances are AWS’s way to sell off unused server capacity when demand isn’t high. They are much cheaper, but come with a lot of restrictions, such as being interruptable and more complicated to start, stop, and run for longer periods of time.
Restrictions For Stopping a Spot Instance
Spot instances work a lot differently than on-demand or reserved instances. Generally, they’re for short-term workloads that can be interrupted at any time, which makes them mostly suitable for task running or auto-scaling deployments. However, spot instances don’t have to be short-lived—the only real restriction is that the workload must be interruptable, meaning you can run a spot instance as if it were an EC2 instance, as long as you are okay with random restarts.
In practice, restarts don’t happen that often for most instance types, usually at most a few times a month per instance, if even. This means that it’s feasible to use them as a cheaper version of on-demand instances, though reserved instances and EC2 Savings Plans are generally more viable options for long term deployments.
RELATED: Sign Up For AWS’s Savings Plans To Cut Your EC2 Bill In Half
As of January 2020, you are able to stop and restart spot instances. This works exactly like EC2, where the instance is off with the EBS disk still intact for the next restart. Though, to be able to stop and restart running spot instances, they will need to meet the following criteria:
They must not be part of an auto-scaling group They must be EBS-backed The instance request must be marked as “persistent“
Thepersistent modifier can be chosen when launching the spot instance, and simply means that in the event of an interruption by AWS, the spot instance will automatically restart. This is usually something you’d like to have on most of the time anyway, especially if you plan on stopping workloads manually.
Stopping Spot Instances
When launching the spot instance, you must select “persistent” under the request settings. This means you can’t select “hibernate” as the shutdown behaviour, but that’s generally not what you’d want anyway for stopping and starting.
Once launched, you’ll find the controls to stop and start the spot instance like normal. Once stopped, it functions exactly like a stopped on-demand instance—the EBS volume remains, and will be used on next restart.
You can also use the stop-instances command from the AWS CLI to stop instances from a script.