Is there a way that Amazon Web Services EC2 instances can be self terminating? Does Amazon have anything that allows an instance to terminate itself ("Hara-Kiri") after running for more than say an hour? I could change the scripts on the running instance to do this itself, but that might fail and I don't want to edit the image, so I would like Amazon to kill the instance.
If you want to assign it as Self-Stopping on Self-Terminating, you can do it one time only. In your EC2 Console go to Instance Settings, change Shutdown Behavior to Stop.
The key difference between stopping and terminating an instance is that the attached bootable EBS volume will not be deleted. The data on your EBS volume will remain after stopping while all information on the local (ephemeral) hard drive will be lost as usual.
Amazon EC2 Auto Scaling might terminate instances in an Auto Scaling group for the following reasons: The instance is marked as unhealthy. The instance exceeded its specified keep-alive parameters. There is an Auto Scaling group scale down event.
To have an instance terminate itself do both of these steps:
--instance-initiated-shutdown-behavior terminate
or the equivalent on the AWS console or API call.Run shutdown -h now
as root. On Ubuntu, you could set this up to happen in 55 minutes using:
echo "sudo halt" | at now + 55 minutes
I wrote an article a while back on other options to accomplish this same "terminate in an hour" goal:
Automatic Termination of Temporary Instances on Amazon EC2
http://alestic.com/2010/09/ec2-instance-termination
The article was originally written before instance-initiated-shutdown-behavior
was available, but you'll find updates and other gems in the comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With