prevent an ec2 instance from shutting down
I started a couple of instances yesterday and today none of them were visible in the AWS console nor I was able to access them using PuTTY even though I saved the session.
I'm assuming those have been shut down by some process even if I have no way to check if it's so.
now I would like to know if there is a way to keep an instance running unless I explicitly enter some commands to shut down the machine.
You can enable termination protection on instances which may help.
I would investigate and find out why those instances were terminated - start with CloudTrail as it shows things such as EC2 API calls (even those made via the console) so you can determine the root cause.
You can implement instance termination protection for Amazon EC2 instances which provides an additional layer of protection. Here is an AWS knowledge document on best practices for preventing the loss of data on termination: https://aws.amazon.com/premiumsupport/knowledge-center/accidental-termination/. The first link on this page refers you to this page, https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/terminating-instances.html#Using_ChangingDisableAPITermination, which covers instance termination protection.
Relevant questions
prevent an ec2 instance from shutting down
asked 5 months agoEC2 instance stuck in "shutting-down"
Accepted Answerasked 3 years agoInstances stuck in shutting down
Accepted Answerasked 3 years agoec2 instance down twice today
asked a year agoEC2 instance shutting down for more than 2 days
Accepted Answerasked 3 years agoInstance i-0b03428e27c0fbc41 stuck in shutting-down state
asked 3 years agoMac EC2 instance stuck in "shutting-down" state
asked 5 months agoInstance stuck in shutting down status
asked 3 months agoEc2 Instance won't terminate - stuck in "shutting-down" state
asked 2 years agoEC2 Instance Stuck Shutting Down
asked 2 years ago