Deploying django project to elastic beanstalk using the command line. How to turn health to green?

0

I have been deploying a django project to elastic beanstalk using: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-configure-for-eb When I deploy the environment health is green but after a few minutes it turns red and gives the explanation: "Environment health has transitioned from Ok to Severe. 100.0 % of the requests are erroring with HTTP 4xx. Insufficient request rate (6.0 requests/min) to determine application health. ELB processes are not healthy on all instances. ELB health is failing or not available for all instances"

I can still view the website even though the health is severe. I am not sure how to fix this problem. The service role I use has the permission AdministratorAccess-AWSElasticBeanstalk. The EC2 instance profile I use has the permissions: AWSElasticBeanstalkMulticontainerDocker, AWSElasticBeanstalkWebTier and AWSElasticBeanstalkWorkerTier

Johan
asked 3 months ago238 views
1 Answer
1

Hello.

Elastic Beanstalk environment's health status 'Severe [1]' means the health agent is reporting a very high number of request failures or other issues for an instance or environment.

According to the message you share, your application seems not responding well (returning 4XX HTTP response code) to health check job from ELB.

Please check health check policy for your Elastic Beanstalk environment and confirm If your environment responds well to the health check process.

By default, path for health check process is '/health' and desirable response is '200'.

So you will need to check how your application responds to requests from '/health' path and modify If your application doesn't respond with '200' for the requests from the above path.

Reference: [1] Health colors and statuses - Severe (red)

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/health-enhanced-status.html#health-enhanced-status-severe

profile picture
EXPERT
answered 3 months ago
  • Hi! I was checking web.stdout.log and it kept coming saying Invalid HTTP_HOST header: '172.31.31.20'. You may need to add '172.31.31.20' to ALLOWED_HOSTS. So I added that to ALLOWED_HOSTS and then the health went from "severe" to "ok". I don't really know why that fixed the health, do you? When i checked the url "domain/health" I only got 404 error. I still think there is something wrong even though it says the health is ok. The web.stdout.log is displaying: Jan 22 04:31:25 ip-172-31-31-20 web[6877]: Bad Request: / Jan 22 04:43:45 ip-172-31-31-20 web[6877]: Invalid HTTP_HOST header: '13.49.254.128'. You may need to add '13.49.254.128' to ALLOWED_HOSTS. Jan 22 04:43:45 ip-172-31-31-20 web[6877]: Traceback (most recent call last): Jan 22 04:43:45 ip-172-31-31-20 web[6877]: File "/var/app/venv/staging-LQM1lest/lib64/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner Jan 22 04:43:45 ip-172-31-31-20 web[6877]: response = get_response(request) Jan 22 04:43:45 ip-172-31-31-20 web[6877]: File "/var/app/venv/staging-LQM1lest/lib64/python3.9/site-packages/django/utils/deprecation.py", line 133, in call Jan 22 04:43:45 ip-172-31-31-20 web[6877]: response = self.process_request(request) Jan 22 04:43:45 ip-172-31-31-20 web[6877]: File "/var/app/venv/staging-LQM1lest/lib64/python3.9/site-packages/django/middleware/common.py", line 48, in process_request Jan 22 04:43:45 ip-172-31-31-20 web[6877]: host = request.get_host() Jan 22 04:43:45 ip-172-31-

  • This is because django application manages allowed list for 'ALLOWD_HOSTS' addresses in order to protect HTTP Host header attacks. But this logic will prevent ELB from checking your application's health status with each EC2 instance's private IP address, so you will need to allow its private IP address to each instance. You can add some logic to get private IP address by retrieving instance metadata and parse 'local-ipv4' data, then add the address to your application's allowed list.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions