Amazon ElasticBeanstalk Health Check URL

I have been working on developing and deploying an application to Amazon ElasticBeanstalk over the last few weeks. I love the environment and the fact that it has the benefits of a true Platform as a Service (PaaS) but also the power of Infrastructure of a Service (IaaS) should I require. One of the things that Beanstalk does is to check application health periodically and can email the administrator an alert if things are not healthy.

So how does Beanstalk monitor applications ? Firstly, based on a configurable period ( default 30 seconds) but up to 5 minutes, a request to a health check URL is sent. This is a HTTP HEAD request and a response of 200 OK is expected. Application status is considered to be in one of four states based on the response to the request:

  • Green – application has responded to health check URL in last minute
  • Yellow – No response to health check URL in last five minutes
  • Red – No response for more than 5 minutes
  • Grey – Status unknown

If an application is found to be in an unhealthy state then an alert email is sent. The health check URL is used at two levels. One at the load balancer level for the whole application and secondly on individual server instances behind the load balancer. Should an individual instance fail to respond for 10 consecutive health check requests then the instance is automatically terminated and a new one started as part of the auto scaling.

The default URL for the health check is /. This can be overridden and it is often appropriate to provide a custom URL for the health check so that the load on the server is minimal. Requesting the home page just for the HEAD section is not a sensible thing in most cases. My application is using Spring MVC so I have added a simple Controller with a health check URL that is shown below:

@Controller
public class HealthCheckController {
    @RequestMapping(value="/healthcheck", method=RequestMethod.HEAD)
    public void healthCheck(HttpServletResponse response) {
        response.setContentLength(0);
        response.setStatus(HttpServletResponse.SC_OK);
    }
}

Working with Elastic Beanstalk and Amazon AWS in general is exciting but requires a thorough understanding of all the components and how they can be integrated to form a coherent whole. Learning Tree have developed a four day course that explains how to effectively use Amazon AWS to its maximum potential. If you are interested in AWS, why not consider attending. The course has been developed by Cloud and Security expert Steve Lockwood and details can be found here.

Chris Czarnecki

Type to search blog.learningtree.com

Do you mean "" ?

Sorry, no results were found for your query.

Please check your spelling and try your search again.