客户请求XX小时EC2实例。 我创建了一个按需EC2实例,并将凭据发送给用户。他将其用于短期计算。 我该如何在XX小时后完全终止该EC2实例?
谢谢。
答案 0 :(得分:0)
在给定时间段后终止实例的最简单方法是:
sleep 3600; shutdown now -h
此外,在启动实例时,请设置Shutdown Behavior = Terminate
。这意味着当实例从实例内部停止时,它实际上将被终止。
或者,您可以编写一个 Stopinator ,该触发器有时会触发并确定要停止/终止的实例。有关示例,请参见:Simple Lambda Stopinator: Start/Stop EC2 instances on schedule or duration
答案 1 :(得分:0)
谢谢约翰(@ john-rotenstein)。
我测试了您的所有建议。
我将以下用户数据脚本用于
Windows实例:
<script>
shutdown -s -t 3600
</script>
<persist>true</persist>
Linux实例:
...
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
sleep 3600
shutdown now -h
此外,第2类Stopinator对我来说效果很好,但仅使用Stop-After标签