如何在不活动时自动关闭服务器,例如在没有SSH连接的情况下30分钟后?
当然,我正在寻找最简单的解决方案.每小时左右检查也可以,只是可靠的工作.
解决方法
Today we are giving you the ability to stop or terminate your EC2
instances when a CloudWatch alarm is triggered. You can use this as a
failsafe (detect an abnormal condition and then act) or as part of
your application’s processing logic (await an expected condition and
then act). [emphasis mine]
您的用例特别列在故障安全提示部分中:
If you (or your developers) are forgetful,you can detect unused EC2
instances and shut them down. You could do this by detecting a very
low load average for an extended period of time. This type of failsafe
could be used to reduce your AWS bill by making sure that you are not
paying for resources you’re not actually using.
如上所述,这取决于能够启发式地检测触发警报和停止实例的适当条件 – 您可以根据登录的SSH用户数,空闲时间或其他方式通过Publishing Custom Metrics将其带到CloudWatch的下一级别.依次获得所需检测和关闭过程的更多控制/精度.