自行终止 AWS EC2 实例? [英] Self-Terminating AWS EC2 Instance?
问题描述
Amazon Web Services EC2 实例是否可以自我终止?亚马逊是否有任何东西可以让实例在运行一个多小时后自行终止(Hara-Kiri")?我可以更改正在运行的实例上的脚本以自己完成此操作,但这可能会失败并且我不想编辑图像,因此我希望亚马逊终止该实例.
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.
推荐答案
要让实例自行终止,请执行以下两个步骤:
To have an instance terminate itself do both of these steps:
- 使用
--instance-initiated-shutdown-behavior terminate
或 AWS 控制台或 API 调用上的等效项启动实例. 以 root 身份运行
shutdown -h now
.在 Ubuntu 上,您可以使用以下方法将其设置为在 55 分钟内发生:
- Start the instance with
--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:
自动终止 Amazon EC2 上的临时实例
http://alestic.com/2010/09/ec2-instance-termination
Automatic Termination of Temporary Instances on Amazon EC2
http://alestic.com/2010/09/ec2-instance-termination
这篇文章最初是在 instance-initiated-shutdown-behavior
可用之前编写的,但您会在评论中找到更新和其他精华.
The article was originally written before instance-initiated-shutdown-behavior
was available, but you'll find updates and other gems in the comments.
这篇关于自行终止 AWS EC2 实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!