如何从自身内部检测AWS实例的状态? [英] How to detect state of aws instance from inside of itself?

查看:93
本文介绍了如何从自身内部检测AWS实例的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EC2中具有自动伸缩组,我想在实例终止时检测实例的状态,以便可以在终止之前开始导出日志文件.

I have auto scaling group in EC2 and I want to detect the state of the instance when it is getting terminated, so that I could start exporting log files before it will be terminated.

我知道一种实现此目的的方法是使用自动缩放生命周期挂钩,但是根据我的理解,我将不得不使用外部监视器,然后必须将其装入实例并导出日志文件.理想情况下,我想找到一种从内部检测实例状态的方法(当自动伸缩组发送命令终止该实例时),这样它就可以自行进行导出,而无需与任何其他实例进行通信.任何人都会知道是否有可能这样做,如果可以的话,我应该从哪里开始?

I know a way to do this is use autoscaling lifecycle hooks but from my understanding I would have to use external monitor which would then have to ssh into instance and do the export of log files. Ideally I would like to find a way on how to detect state of instance from inside (when the auto scaling group sends command to terminate it) so it would do the export on its own without communicating with any other instances. Anyone would know if its possible to do this, if so where could I begin?

推荐答案

我还没有尝试过,但这可能有用...

I haven't tried it, but this might work...

生命周期挂钩可以向 SNS 发送通知.然后,这可能会将消息发送到 HTTP端点,该消息可能是您在服务器上运行的Web应用程序.然后,该应用程序可以执行您想要的关闭活动.

The lifecycle hook can send a notification to SNS. This could then send a message to an HTTP Endpoint, which could be a web application you have running on the server. The application could then perform the shutdown activities you desire.

这篇关于如何从自身内部检测AWS实例的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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