Reputation: 11
I am trying to deploy a Django app to Elastic Beanstalk. I used AWS CodePipeline as my CI/CD process. The instance is able to successfully deploy, but when I click on the domain it gives me a 502 gateway error. I suspect this is from the Gunicorn server not running.
My environment platform is Python 3.11 Linux 2023.
I suspect that the Gunicorn is not running since it cannot find my WSGIPath because of the way my AWS CodePipeline is setup. AWS CodePipeline reads from my repository which has a 'node' folder (containing my frontend) and a 'python' folder (containing my Django app). My 'python/.ebextensions/django.config' contains the following configuration:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: myproject.wsgi:application
I am guessing that my path is not set correctly since 'myproject' isn't at the root level. And so, I tried the following configuration as well:
option_settings:
aws:elasticbeanstalk:application:environment:
PYTHONPATH: "/opt/python/current/app/python:$PYTHONPATH"
DJANGO_SETTINGS_MODULE: myproject.settings
aws:elasticbeanstalk:container:python:
WSGIPath: myproject.wsgi:application
This still gives me a 502 error so I am not sure where to proceed from here. I am confused as to how to properly set my PYTHONPATH so that 'myproject' is found. I cannot find the documentation as to what path the application files are stored. '/opt/python/current/' and '/var/app/current' come up from what I have researched.
Upvotes: 0
Views: 133
Reputation: 11
I managed to figure a way around this by using a custom Procfile:
web: gunicorn --bind :8000 --workers 3 --threads 2 --pythonpath python myproject.wsgi:application
Make sure Procfile is root level.
Upvotes: 0