How to make an EC2 instance automatically reboot when ELB says it's unavailable?

I got a cheap EC2 micro instance and wrote a simple script that lists all my servers on EC2, and does a GET on each one to make sure that it's functioning properly. If a server isn't functioning properly, my script reboots it. I have the script running once every 10 minutes.

Woulda been slightly easier if there were a service out there to do this for me, but the system was easy to set up and the micro instance is cheap.


Use autoscaling group and set it to keep 1 live instance. If your instance crashes it will spawn a new one from predefined instance image. It's easy and convenient.


Agree with @agmin that a lambda function is a great way to do this. You can configure a CloudWatch alarm to trigger the lambda function via an SNS topic.

I put this implementation together and it seems to be working well. It can be set up and configured entirely via the command line:

https://github.com/jcowley/elb-instance-reboot