自行终止的AWS EC2实例?实例、AWS

2023-09-11 23:36:57 作者:单身的人光芒万丈

有没有一种方式,亚马逊网络服务EC2实例可自行终止?亚马逊是否有任何允许实例在运行多说,一个小时后自行终止(切腹)?我可以改变脚本的运行实例来做到这一点本身,但可能会失败,我不想要编辑的图像,所以我想亚马逊杀实例。

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启动关机 - 行为终止或在AWS控制台或API调用等效启动实例。

Start the instance with "--instance-initiated-shutdown-behavior terminate" or the equivalent on the AWS console or API call.

运行关机现在-h为根。在Ubuntu上,你可以设置此使用的情况发生在55分钟内:

Run "shutdown -h now" as root. On Ubuntu, you could set this up to happen in 55 minutes using:

回声命令叫停|在现在+ 55分

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

这篇文章最初是前实例启动,关机,行为可用,但你会发现更新和其他宝石的意见。

The article was originally written before instance-initiated-shutdown-behavior was available, but you'll find updates and other gems in the comments.