Using Load Balancer health checks with AWS Elastic Beanstalk

By default Elastic Beanstalk environments use the instance health checks when deciding if an instance is still responsive. The load balancer will be checking a HTTP endpoint to decide if an instance is still responsive.

This can lead to scenarios where the server is "healthy" e.g. has power going to it, but the application is unresponsive, so instances are removed from the load balancer, but the auto scaling group does not replace them as it still sees them as healthy. The C drive running out of disk space is a good example of this, IIS stops serving requests, but the machine itself is still on.

To solve this problem you can make the autoscaling get the instance status from the load balancer, e.g. if the load balancer marks an instance as unhealthy the autoscaling group will terminate it, and start a replacement in its place.

If you expect your application to regularly fail its load balancer health checks, this may not be the solution, and in the event of an outage to another part of your system (e.g. the database) you may find the auto scaling group constantly removing/adding instances, depending on your application this could put more load on your database and make the problem worse, so be aware of these issues. The HealthCheckGracePeriod (in seconds) can be altered to mitigate some of these risks, this will stop the autoscaling group terminating an instance in the first x amount of seconds after it started, this allows for OS startup, application startup etc. and you can alter this based on your applications needs.

To switch to ELB health checks you need to create a directory named .ebextensions in the root of your web application and add the file ELBHealthChecks.config below. If you are using Visual Studio ensure the file is marked as "Content" so that it is copied to the deployment package. The file below is based on this Stack Overflow answer, if you find this useful go and give it an upvote!

  • Post