aws / elastic-beanstalk-roadmap

AWS Elastic Beanstalk roadmap
https://aws.amazon.com/elasticbeanstalk/
Creative Commons Attribution Share Alike 4.0 International
283 stars 11 forks source link

Getting Application Load Balancer IP Address in Env vars #231

Open DataGreed opened 2 years ago

DataGreed commented 2 years ago

I've recently migrated to Amazon Linux 2 from the deprecated version and I am struggling with passing health checks of my Python Application (Django) with application load balancer.

Previously I've been using classic load balancer and all health checks were performed from with HTTP Host header set to localhost, but on Amazon Linux 2 with Application Load balancer HealthChecker sets Host header to Load Balancer's IP Address that is assigned automatically when EB Environment is set up and it can probably change.

Django performs a check of every request against the list of allowed host headers and if the host is not in the list it responds with a 400 error.

I've hardcoded the Load Balancer IP address in the settings as a temporary measure, but it seems logical to get this IP address at runtime from environment variables since it can change.

How can I do that? Or is there a better way to approach this problem? E.g. is it possible to remove the Host header of the Health Checker or or change its value?

nickdnk commented 2 years ago

@DataGreed You should be able to filter requests that don't match any host headers you want in the load balancer itself, instead of having the application handle that. You can configure this under Load Balancers -> Listening -> View/edit rules. I don't know if that works for you, but it's an option at least.