自行终止 AWS EC2 实例? [英] Self-Terminating AWS EC2 Instance?

查看:44
本文介绍了自行终止 AWS EC2 实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:

  1. 使用 --instance-initiated-shutdown-behavior terminate 或 AWS 控制台或 API 调用上的等效项启动实例.
  2. 以 root 身份运行 shutdown -h now.在 Ubuntu 上,您可以使用以下方法将其设置为在 55 分钟内发生:

  1. Start the instance with --instance-initiated-shutdown-behavior terminate or the equivalent on the AWS console or API call.
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆