How to restart EC2 instance from CloudWatch alarm

2019-05-27 05:05发布

Sometimes my application dies w/o any reason and I can detect that using CloudWatch and CPU usage metric going down. At this moment I want to restart the java application or the whole EC2 instance. Any suggestions how can I achive that?

3条回答
Evening l夕情丶
2楼-- · 2019-05-27 05:23

If only your application halt but EC2 instance works.

You could write a shell monitor the app using CloudWatch API and shoot the app when necessary,then make it a task in cron. Or you can using a shell right in your EC2 instance.

To restart your EC2 instance automatically is way too dangerous ,you can try Autoscaling, which automatically starts a new instance when your instance frozen and keep your SLA.

查看更多
三岁会撩人
4楼-- · 2019-05-27 05:40

You can let CloudWatch terminate your EC2 instance and let AutoScaling bring up another "fresh" instance with your application configured.

查看更多
登录 后发表回答