0

I follow all the instructions on the official AWS website, but I still get the same error. I have tried several projects, each on the local server works quite normally as soon as it starts on AWS I get the next error 502 Bad Gateway.

  • this seams like main problem : ModuleNotFoundError: No module named 'ebddjango/wsgi'

wsg file:

import os from django.core.wsgi 
import get_wsgi_application 
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ebddjango.settings') application = get_wsgi_application() 

config:

option_settings: 
aws:elasticbeanstalk:container:python: 
WSGIPath: ebddjango/wsgi:application

Status:

  Updated: 2022-01-27 14:19:09.259000+00:00
  Status: Ready
  Health: Red

Erorr log

Jan 27 14:49:19 ip-172-31-8-170 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jan 27 14:49:19 ip-172-31-8-170 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jan 27 14:49:19 ip-172-31-8-170 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jan 27 14:49:19 ip-172-31-8-170 web: ModuleNotFoundError: No module named 'ebddjango/wsgi'
Jan 27 14:49:19 ip-172-31-8-170 web: [2022-01-27 14:49:19 +0000] [4399] [INFO] Worker exiting (pid: 4399)
Jan 27 14:49:19 ip-172-31-8-170 web: [2022-01-27 14:49:19 +0000] [4392] [INFO] Shutting down: Master
Jan 27 14:49:19 ip-172-31-8-170 web: [2022-01-27 14:49:19 +0000] [4392] [INFO] Reason: Worker failed to boot.
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4407] [INFO] Starting gunicorn 20.1.0
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4407] [INFO] Listening at: http://127.0.0.1:8000 (4407)
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4407] [INFO] Using worker: gthread
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4414] [INFO] Booting worker with pid: 4414
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4414] [ERROR] Exception in worker process
Jan 27 14:49:20 ip-172-31-8-170 web: Traceback (most recent call last):
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
Jan 27 14:49:20 ip-172-31-8-170 web: worker.init_process()
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
Jan 27 14:49:20 ip-172-31-8-170 web: super().init_process()
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
Jan 27 14:49:20 ip-172-31-8-170 web: self.load_wsgi()
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
Jan 27 14:49:20 ip-172-31-8-170 web: self.wsgi = self.app.wsgi()
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
Jan 27 14:49:20 ip-172-31-8-170 web: self.callable = self.load()
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
Jan 27 14:49:20 ip-172-31-8-170 web: return self.load_wsgiapp()
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
Jan 27 14:49:20 ip-172-31-8-170 web: return util.import_app(self.app_uri)
Jan 27 14:49:20 ip-172-31-8-170 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
Jan 27 14:49:20 ip-172-31-8-170 web: mod = importlib.import_module(module)
Jan 27 14:49:20 ip-172-31-8-170 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
Jan 27 14:49:20 ip-172-31-8-170 web: return _bootstrap._gcd_import(name[level:], package, level)
Jan 27 14:49:20 ip-172-31-8-170 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jan 27 14:49:20 ip-172-31-8-170 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jan 27 14:49:20 ip-172-31-8-170 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jan 27 14:49:20 ip-172-31-8-170 web: ModuleNotFoundError: No module named 'ebddjango/wsgi'
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4414] [INFO] Worker exiting (pid: 4414)
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4407] [INFO] Shutting down: Master
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4407] [INFO] Reason: Worker failed to boot.
Jan 27 14:49:20 ip-172-31-8-170 web: [2022-01-27 14:49:20 +0000] [4422] [INFO] Starting gunicorn 20.1.0
-- More  --
Luiz
  • 1,985
  • 6
  • 16
  • Hi, are you using .ebextensions folder with .config files? – Luiz Jan 27 '22 at 16:24
  • Please edit your answer and show me your config file and if is possible your ebddjango/wsgi.py file – Luiz Jan 27 '22 at 18:18
  • import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ebddjango.settings') application = get_wsgi_application() config: option_settings: aws:elasticbeanstalk:container:python: WSGIPath: ebddjango/wsgi:application – Nemanja Pavlovic Jan 27 '22 at 18:29

2 Answers2

1

Seems I had exactly the same problem: I was following the official tutorial but it was ending up with a 502 error. I found my solution on here, where they said:

It's true that Python 3.7+ on Amazon Linux 2 platform needs gunicorn.

So what I did was simply running the following command just after installing django (point 3 of the Set up a Python virtual environment and install Django section of the tutorial)

pip install gunicorn
General Grievance
  • 4,555
  • 31
  • 31
  • 45
jnk
  • 33
  • 1
  • 5
0

In your .config file try

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: ebddjango.settings
  aws:elasticbeanstalk:container:python:
    WSGIPath: ebddjango.wsgi:application
  aws:elasticbeanstalk:environment:proxy:staticfiles:
    /static: static
Luiz
  • 1,985
  • 6
  • 16
  • now :ModuleNotFoundError: No module named 'application' – Nemanja Pavlovic Jan 27 '22 at 20:52
  • Alot of things can throw this error, but it can be your settings file that is not setting for production as here https://stackoverflow.com/questions/70332515/elastic-beanstalk-django-app-deployment-502-bad-gateway-server-not-running-no-m or you can be zipping your files wrong, you should zip your files not your folder as says here https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html or it can be differences between python versions https://stackoverflow.com/questions/62479386/no-module-named-application-error-while-deploying-simple-web-app-to-elastic-be – Luiz Jan 27 '22 at 21:12
  • I tested with a completely empty django project . 2 times I went through comand promt, starting the project of everything and pushing on AWS 502. after that I went with zipping and uploading via aws console, each time the result was the same 502. Thank you for good input i will cheek setings.py file to see whats happening in there , it may be the issue with not for depployement settings . – Nemanja Pavlovic Jan 28 '22 at 07:59