[Solved]-AWS Elastic Beanstalk health check issue


As far as I know, 502 Bad Gateway error can be mitigated only by manually checking the major links you have on your websites and if they are accessible through a simple GET request.

In case of my website, I had some issue with the login page and an about page, (and it was about 33% of my website sadly) which is why after uploading to EC2 i got a 5xx error on health check. I solved the problem by simply making the links work on the server (there were some functionalities which were only running on localhost and not on AWS so I fixed that and got OK status in Health Check)

I don’t think there is a point in removing health check as it gives vital information about your website and you probably don’t want your website to have inaccessible pages.

Keep track of logs to narrow down to the problem.

I hope you find the solution.


While your code is being deployed, you will get 502 because the EC2 instance fails the health check call. You need to adjust the load balance health check default settings to allow enough time for your deployment to complete. Allow more time for a deployment if you also restart the server after each deployment.

The AWS load balancer sends a health check request to each registered instance every N seconds using the path you specify. The default interval seconds is 30 seconds. If the health check fails N number of times (default is 2) for any of the instances you have running, health changes to Degraded or Severe depending on the percentage of your instances that are not responding.

  1. Send a request that should return a 200 response code. Default is ‘/index.html’
  2. Wait for N seconds before time out (default 5 seconds)
  3. Try again after N interval seconds (default 30 seconds)
  4. If N consecutive calls fail, change the health state to warning or severe (default unhealthy threshold is 2)
  5. After N consecutive successful calls, return the health state to OK (default is 10).

With the default settings, if any web server instance is down for more than a minute (2 tries of 30 seconds each), it is considered an outage. It will take 5 minutes (10 tries every 30 seconds) to get back to Ok status.

For a detailed explanation and configuration options please check AWS documentation: Configure Health Checks for Elastic Load Balancing

Leave a comment