Preventing an auto-terminated spot instances from restarting - amazon-web-services

Imagine I have a persistent spot request of size 1. If I manually stop this instance, it will not restart until I start it again.
However, if the instance is interrupted by AWS because of a lack of spot capacity, it will restart automatically when capacity is available (as I understand it).
How can I put an instance in the stopped-because-interrupted state into a state where it will not restart automatically if capacity becomes available.

According to AWS documentation only EC2 can start interrupted spot instances so I think that the only option would be monitoring events/alerts which notify when instances restart and then stop them again with automation. Never tried this si this is only an educated guess/opinion.

Related

Will spot service start a manually stopped spot instance

I'm aware that the spot service will manage a spot instance and stop or start it based on whether the price matches or capacity is available as per https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html#specifying-spot-interruption-behavior
And https://aws.amazon.com/about-aws/whats-new/2020/01/amazon-ec2-spot-instances-stopped-started-similar-to-on-demand-instances/
mentions now it's possible to manually stop or start a spot instance.
I'm confused if I stop a spot instance manually, will the spot service start it again whenever the price/capacity requirements are met? Or would it stop monitoring the instance till I manually start the spot instance again?
To answer your question, there are 2 kinds of request. 1) one time request 2) persistent request.
one-time-request:- manually you can only terminate instance, you cannot stop it.Once you terminate instance the request goes away.
persistent-request:- In case of persistent request, it will automatically launch an instance when you manually terminate the instance, but if you stop it manually then you need to manually start it again. spot instance will not start for you automatically.docs
If the request is persistent, the request is opened again after your Spot Instance is interrupted( interruption by aws). If the request is persistent and you stop your Spot Instance, the request only opens after you start your Spot Instance.
Please NOTE
You can only stop/ start instance which is launched from persistent request and which not a part of fleet or launch group, Availability Zone group, or Spot block. docs
when you stop the instance the request goes into disabled state.

Unable to launch EC2 instance even after deleting CloudWatch

I just figured out about AWS CloudWatch that would let you terminate your EC2 instance after some time in inactivity. So I created an alarm that would terminate the instance when the CPU usage is less the 1% for 2 hours. Which ultimately ended up putting my instance into an alarm state right away and it prevented me from starting it up to test the feature out.
I then deleted the CloudWatch alarm again in order to be able to launch the EC2 instance gain but even after I deleted the CloudWatch, the state is set to Terminated but the but the Start option from the Actions drop down button is still disabled.
How do I get the instance to start again?
You can't restart a terminated instance. The instance no longer exists. It is just listed as "terminated" in your web console for a little bit so you can see that it was deleted. You have to create a new instance now.

how to test stop start of AWS Spot Instances

I am creating AWS spot instances on demand and wanted to keep interruption behavior as STOP, so that AWS can restart my VM as soon as price/demand meets.
But the problem is AWS GUI doesn't have any option to STOP running spot instances.
It just have option to terminate instances or cancel spot requests.
I am developing some application which will resume itself on reboot.
I wanted to test the application by simulating AWS stop and restart behaviour.
Thx in advance
~Ashish
As of now you cannot Stop a Spot Instance.
To simulate your application behavior, bid for minimum and wait for AWS to interrupt the instance.
Make sure that your spot instance is Stop Interruption ready.
Reference:
Spot Instance Interruptions
You do not have an option to restart a SPOT instance. SPOT instance is not the right candidate for this kind of application.

EC2 Spot instance Maximum runtime

I read myself pretty much through all the online docs of EC2.
Still one question is unanswered to me:
What is the maximum runtime of a spot instance (uninterrupted) ?
everything is well documented for < 6h runtime. But what happens afterwards ? is the instance automatically terminated or does is keep running until the ressources are no more available ? somehow i didn`t find anything clear on this.
Thanks !
As mentioned in the AWS documentation under How Spot Instances Work:
Spot Instances run until you terminate them or until Amazon EC2 must interrupt them (known as a Spot Instance interruption).
Therfore in theory an EC2 spot instance will run indefinitely until you terminate it or AWS interrupts it because your spot bid price is too low, or similar.
Spot instances will not terminate until you do or it is interrupted from AWS side (Eg. The Spot price is greater than your maximum price). So your application should be able to handle these terminations gracefully.
More details : https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html
Also if you terminate it you will be charge for that hour. If AWS terminates it you are not charged for that hour.

EC2 Spot instances: How to start tasks, how to stop them?

I have a long batch job that I'd like to run on AWS EC2 Spot Instances, to save money. However, I can't find the answer to two seemingly critical questions:
When a new instance is created, I need to upload the code onto it, configure it, and run the code. How does that get done for Spot Instances, which are created automatically and unattatendly?
When an instance is stopped, I would prefer having some type of notification, so that the state could be saved. (This is not critical, as the batch job will run fine if terminated suddenly - but a clean shutdown is preferred).
What is the standard way to deploy spot instances? Is there a way to do manual setup, turn it into a spot instance, and then let it hibernate until the spot price is available?
As to #1, if you create an AMI (amazon machine image), you can have everything you want pre-installed on a 'hibernating' image that you can use as a basis for the spot image you start:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-getting-started.html
For #2, you can be notified when a spot instance terminates using SNS:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-autoscaling-notifications.html
http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/ASGettingNotifications.html
BTW: You can be notified the the instance was terminated, but only after it terminates. You can't get notified that an instance is about to be shutdown and gracefully save the state - you need to engineer your solution to be OK with unexpected shutdowns.
No matter how high you bid, there is always a risk that your Spot
Instance will be interrupted. We strongly recommend against bidding
above the On-Demand price or using Spot for applications that cannot
tolerate interruptions.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-protect-interruptions.html
You can use the user data settings to download from a specific repository a script and run it at the first instance startup.
As E.J. Brennan said: you can use SNS