WSGI configuration for Django Deployment using EB CLI

0

I'm trying to deploy a Django 3.2 project. I've created the virtual environment and I've tested it locally successfully. It's based on Python 3.11 and therefore is running on 64bit Amazon Linux 2023/4.0.1. Following this tutorial, I try to deploy it, receiving a 502 error. Checking the logs (/var/log/web.stdout.log), I find this:

Traceback (most recent call last):
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
   worker.init_process()
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
   super().init_process()
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
   self.load_wsgi()
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
   self.wsgi = self.app.wsgi()
               ^^^^^^^^^^^^^^^
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
   self.callable = self.load()
                   ^^^^^^^^^^^
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
   return self.load_wsgiapp()
          ^^^^^^^^^^^^^^^^^^^
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
   return util.import_app(self.app_uri)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/var/app/venv/staging-LQM1lest/lib64/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
   mod = importlib.import_module(module)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/lib64/python3.11/importlib/__init__.py", line 126, in import_module
   return _bootstrap._gcd_import(name[level:], package, level)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
 File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
 File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'application'
[INFO] Worker exiting (pid: 2823)
[INFO] Shutting down: Master
[INFO] Reason: Worker failed to boot.

As far as I think, it could be due to the .ebextensions/django.config file. I've structured it with the next format:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: chat/wsgi.py

and I've changed the last line by WSGIPath: chat.wsgi:application and WSGIPath: chat.wsgi as well.

Is this a problem with the .ebextensions/django.config file or is the error in another place?

1 Antwort
0

Based on the error message, it seems that the Gunicorn worker failed to boot because it couldn't find the WSGI application. The error message specifically says "ModuleNotFoundError: No module named 'application'". This suggests that the WSGI application specified in the WSGIPath setting is not being found.

In your .ebextensions/django.config file, you have tried changing the WSGIPath setting to chat.wsgi:application and chat.wsgi. However, the correct format for the WSGIPath setting depends on the structure of your Django project.

Assuming that your Django project is structured like this: project_name/chat/wsgi.py

where project_name is the name of your Django project, then the correct WSGIPath setting would be:

option_settings: aws:elasticbeanstalk:container:python: WSGIPath: project_name.chat.wsgi:application

beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen