Scenario:
- I'm running an EC2 instance behind an auto-scaling group, but I'm not using an ELB.
- Inside the EC2 instance, a docker container with a web server is running.
I would like to add a simple health check that the web server does still respond, so if the docker container goes down, the auto scaling group can replace the instance.
From what I see, only the ELB supports custom health checks. As I don't need an ELB, I wonder if it makes sense to run the health check inside the EC2 instance with a cron job. If the web server does not respond (locally), it can set the health status like this:
export INSTANCE=$(curl http://169.254.169.254/latest/meta-data/instance-id)
export AWS_DEFAULT_REGION=$(curl http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}')
aws autoscaling set-instance-health --instance-id $INSTANCE --health-status Unhealthy
I think, it should work, but it looks a bit complicated, though. Is there a better way to implement custom health checks (without using an ELB)?