Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
885 views
in Technique[技术] by (71.8m points)

python - AWS beanstalk + Django: 502 Bad Gateway - ModuleNotFoundError: No module named 'application'

I'm trying to deploy Django project to Elastic Beanstalk. I'm following their guide: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html But after eb open all pages return "502 Bad Gateway".

My AWS admin shows django environment as "Degraded". Please see the screenshot: enter image description here

My logs, seems like something with "ModuleNotFoundError: No module named 'application'":

----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Jan 27 19:30:21 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jan 27 19:30:21 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jan 27 19:30:21 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jan 27 19:30:21 ip-172-31-32-137 web: ModuleNotFoundError: No module named 'application'
Jan 27 19:30:21 ip-172-31-32-137 web: [2021-01-27 19:30:21 +0000] [3483] [INFO] Worker exiting (pid: 3483)
Jan 27 19:30:21 ip-172-31-32-137 web: [2021-01-27 19:30:21 +0000] [3476] [INFO] Shutting down: Master
Jan 27 19:30:21 ip-172-31-32-137 web: [2021-01-27 19:30:21 +0000] [3476] [INFO] Reason: Worker failed to boot.
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3488] [INFO] Starting gunicorn 20.0.4
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3488] [INFO] Listening at: http://127.0.0.1:8000 (3488)
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3488] [INFO] Using worker: threads
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3495] [INFO] Booting worker with pid: 3495
Jan 27 19:30:22 ip-172-31-32-137 web: [2021-01-27 19:30:22 +0000] [3495] [ERROR] Exception in worker process
Jan 27 19:30:22 ip-172-31-32-137 web: Traceback (most recent call last):
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
Jan 27 19:30:22 ip-172-31-32-137 web: worker.init_process()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
Jan 27 19:30:22 ip-172-31-32-137 web: super().init_process()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
Jan 27 19:30:22 ip-172-31-32-137 web: self.load_wsgi()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
Jan 27 19:30:22 ip-172-31-32-137 web: self.wsgi = self.app.wsgi()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
Jan 27 19:30:22 ip-172-31-32-137 web: self.callable = self.load()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
Jan 27 19:30:22 ip-172-31-32-137 web: return self.load_wsgiapp()
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
Jan 27 19:30:22 ip-172-31-32-137 web: return util.import_app(self.app_uri)
Jan 27 19:30:22 ip-172-31-32-137 web: File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
Jan 27 19:30:22 ip-172-31-32-137 web: mod = importlib.import_module(module)
Jan 27 19:30:22 ip-172-31-32-137 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
Jan 27 19:30:22 ip-172-31-32-137 web: return _bootstrap._gcd_import(name[level:], package, level)
Jan 27 19:30:22 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jan 27 19:30:22 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jan 27 19:30:22 ip-172-31-32-137 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jan 27 19:30:22 ip-172-31-32-137 web: ModuleNotFoundError: No module named 'application'

I guess there might be problem with wsgi configuration.

django.config

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: todo.wsgi

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo.settings')

application = get_wsgi_application()

config.yaml

branch-defaults:
  main:
    environment: django-env
    group_suffix: null
global:
  application_name: todo
  branch: null
  default_ec2_keyname: null
  default_platform: Python 3.7 running on 64bit Amazon Linux 2
  default_region: eu-north-1
  include_git_submodules: true
  instance_profile: null
  platform_name: null
  platform_version: null
  profile: eb-cli
  repository: null
  sc: git
  workspace_type: Application

Would really appreciate some help!

question from:https://stackoverflow.com/questions/65926435/aws-beanstalk-django-502-bad-gateway-modulenotfounderror-no-module-named

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...