一个客户请求一个EC2实例,时间为XX小时.我创建了一个按需EC2实例,我将凭证发送给用户。他将其用于短期计算.我如何才能在XX小时后准确终止该EC2实例?
先谢谢你。
谢谢,John(@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
另外,Stopinator Type 2对我来说工作得很好,但只有在Stop -After标签的情况下。
最简单的方法是在给定的时间段后终止一个实例。
sleep 3600; shutdown now -h
另外,在启动实例时,设置 Shutdown Behavior = Terminate
. 这意味着,当从实例内部停止实例时,它实际上将被终止。
或者,你也可以在实例中编写一个 停止器 触发,并决定哪些实例要停止终止。一些例子见。简单的Lambda Stopinator: StartStop EC2实例的时间表或持续时间。