amazon-web-servicesamazon-ec2aws-sdk

Can I stop a spot instance in aws just like I can stop and start an on demand ec2 instance


I had a use case where I was switching to using spot instances for my application instead of on demand instances. According to my requirement i should be able to stop that instance and restart it just the way we do it for on demand ec2-instances. In the aws console, i only found the option to reboot or terminate my instance and hovering over the stop option said "Spot instance cannot be stopped". Is there a workaround to allow stopping the instance or is it not possible as of now?


Solution

  • Yes. As of February 2020, you can stop and start spot instances at will.

    [Updated: February 2020]

    Per announcement on Jan 13, 2020:

    You can now stop your Amazon EC2 Spot Instances backed by Amazon EBS and start them at will, instead of relying on the “Stop” interruption behavior to stop your Spot Instances when interrupted. Earlier, you could only terminate your Spot Instances but now you can stop your Spot Instances and start them from the user initiated stop state provided Spot capacity is available within your maximum price requirements.

    [Original: September 2018, now deprecated guidance]

    It used to be the case that you could not stop a spot instance at will.

    You could, however, specify that the interruption behavior for a spot instance is "stop" (instead of "terminate"). When an interruption event happens, your instance would be shut down and its state would be saved. When capacity next became available with your price/time requirements, AWS would restart your instance.

    This feature is available for persistent Spot requests and Spot Fleets with the “maintain” fleet option enabled. You are not be charged for instance usage while your instance is stopped.