如何为 Django 应用程序将 Amazon Elastic Beanstalk Linux 1 升级到 Linux 2
Posted
技术标签:
【中文标题】如何为 Django 应用程序将 Amazon Elastic Beanstalk Linux 1 升级到 Linux 2【英文标题】:How to Upgrade Amazon Elastic Beanstalk Linux 1 to Linux 2 for Django Application 【发布时间】:2021-07-02 03:29:27 【问题描述】:我正在尝试将 Django 应用程序从在 64 位 Amazon Linux/2.9.20 上运行的 AWS Elastic Beans Python 3.6 升级到在 64 位 Amazon Linux 2/3.2.0 上运行的 Python 3.8。它在本地运行。当我尝试部署到 Elastic Beanstalk 时,出现以下错误:
Apr 6 10:30:48 ip-172-31-43-9 web: File "/var/app/current/src/core/wsgi.py", line 14, in <module>
Apr 6 10:30:48 ip-172-31-43-9 web: application = get_wsgi_application()
Apr 6 10:30:48 ip-172-31-43-9 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
Apr 6 10:30:48 ip-172-31-43-9 web: django.setup(set_prefix=False)
Apr 6 10:30:48 ip-172-31-43-9 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
Apr 6 10:30:48 ip-172-31-43-9 web: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
Apr 6 10:30:48 ip-172-31-43-9 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
Apr 6 10:30:48 ip-172-31-43-9 web: self._setup(name)
Apr 6 10:30:48 ip-172-31-43-9 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
Apr 6 10:30:48 ip-172-31-43-9 web: self._wrapped = Settings(settings_module)
Apr 6 10:30:48 ip-172-31-43-9 web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
Apr 6 10:30:48 ip-172-31-43-9 web: mod = importlib.import_module(self.SETTINGS_MODULE)
Apr 6 10:30:48 ip-172-31-43-9 web: File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
Apr 6 10:30:48 ip-172-31-43-9 web: return _bootstrap._gcd_import(name[level:], package, level)
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Apr 6 10:30:48 ip-172-31-43-9 web: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Apr 6 10:30:48 ip-172-31-43-9 web: ModuleNotFoundError: No module named 'core'
我的文件结构是:
.ebextensions
01_packages.config
...
.platform/hooks/postdeploy
01_django.sh
src
app1
app2
...
core
folder 1
...
settings
base.py
local.py
aws.py
celery.py
...
wsgi.py
...
core
在INSTALLED_APPS
中。请帮忙
【问题讨论】:
【参考方案1】:期待更好的解决方案,我的临时解决方案是将我的.ebextensions
、.elasticbeanstalk
和.platform
目录下移一级。
看起来像这样
src
.ebextensions
01_packages.config
...
.platform/hooks/postdeploy
01_django.sh
app1
app2
...
core
folder 1
...
settings
base.py
local.py
aws.py
celery.py
...
wsgi.py
...
我使用git push
将之前的主目录保存到 GitHub,然后移动到src
以执行eb deploy
。我对解决方案不满意,并认为它是一种解决方法,直到有人可以给我更好的东西
【讨论】:
以上是关于如何为 Django 应用程序将 Amazon Elastic Beanstalk Linux 1 升级到 Linux 2的主要内容,如果未能解决你的问题,请参考以下文章
如何为 Amazon Web Service 重构 Java Web 应用程序?
如何为 Heroku 应用程序配置带有 SSL 的 Amazon Route
如何为新的 Docker Amazon Linux 2 平台将 Dockerrun.json v2 转换为 Dockerrun.json v3?