无法在 Elastic Beanstalk 上部署 Django 应用程序
Posted
技术标签:
【中文标题】无法在 Elastic Beanstalk 上部署 Django 应用程序【英文标题】:Can't deploy Django application on Elastic Beanstalk 【发布时间】:2015-01-25 10:56:42 【问题描述】:在经历了很多障碍后,我终于将我的代码上传到 AWS Beanstalk,我希望有人可以帮助我解决下一个我看不到解决方案的障碍。
上传后(使用“git aws.push”)它总是会失败。然后我查看了日志,似乎(作为菜鸟)问题是这样的:
'Target WSGI script not found or unable to stat: /opt/python/current/app/topdish'
我认为确实是正确的,我希望它应该在:'/opt/python/ondeck/app/topdish/wsgi.py'
我不知道如何配置它,因为我认为我已经在“.ebextensions”中的“topdish.config”中正确配置了。
container_commands:
01_migrate:
command: "python manage.py syncdb --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: topdish/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: topdish.settings
我在日志中看到的另一个问题是:
'[2014-11-26T23:11:00.070Z] INFO [4168] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Activity execution failed, because: command failed with error code 1: Error occurred during build: Command 01_migrate failed (Executor::NonZeroExitStatus)'
这可能是相关的,或者不相关的。
相关日志:
/var/log/eb-activity.log
inflating: /opt/python/ondeck/app/surveys/static/surveys/css/normalize.css
inflating: /opt/python/ondeck/app/surveys/static/surveys/css/normalize.min.css
creating: /opt/python/ondeck/app/surveys/static/surveys/img/
inflating: /opt/python/ondeck/app/surveys/static/surveys/img/star-empty.png
inflating: /opt/python/ondeck/app/surveys/static/surveys/img/star-filled.png
creating: /opt/python/ondeck/app/surveys/static/surveys/js/
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/data-access-layer.js
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/gklib.js
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/main.js
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/plugins.js
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/polyfils.js
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/tools.js
creating: /opt/python/ondeck/app/surveys/static/surveys/js/vendor/
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/vendor/jquery-1.11.0.min.js
inflating: /opt/python/ondeck/app/surveys/static/surveys/js/vendor/modernizr-2.6.2.min.js
creating: /opt/python/ondeck/app/surveys/templates/
creating: /opt/python/ondeck/app/surveys/templates/surveys/
inflating: /opt/python/ondeck/app/surveys/templates/surveys/index.html
inflating: /opt/python/ondeck/app/surveys/templates/surveys/menu_detail.html
inflating: /opt/python/ondeck/app/surveys/templates/surveys/venue_detail.html
inflating: /opt/python/ondeck/app/surveys/tests.py
inflating: /opt/python/ondeck/app/surveys/urls.py
inflating: /opt/python/ondeck/app/surveys/views.py
creating: /opt/python/ondeck/app/templates/
creating: /opt/python/ondeck/app/templates/admin/
inflating: /opt/python/ondeck/app/templates/admin/base_site.html
creating: /opt/python/ondeck/app/topdish/
extracting: /opt/python/ondeck/app/topdish/__init__.py
inflating: /opt/python/ondeck/app/topdish/app.yaml
inflating: /opt/python/ondeck/app/topdish/settings.py
inflating: /opt/python/ondeck/app/topdish/urls.py
inflating: /opt/python/ondeck/app/topdish/wsgi.py
[2014-11-26T22:56:31.220Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook/03deploy.py] : Starting activity...
[2014-11-26T22:56:35.097Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook/03deploy.py] : Completed activity. Result:
New python executable in /opt/python/run/venv/bin/python26
Not overwriting existing python script /opt/python/run/venv/bin/python (you must use /opt/python/run/venv/bin/python26)
Installing setuptools, pip...done.
--use-mirrors has been deprecated and will be removed in the future. Explicit uses of --index-url and/or --extra-index-url is suggested.
Requirement already satisfied (use --upgrade to upgrade): Django==1.7.1 in /opt/python/run/venv/lib/python2.6/site-packages (from -r /opt/python/ondeck/app/requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): django-uuidfield==0.5.0 in /opt/python/run/venv/lib/python2.6/site-packages (from -r /opt/python/ondeck/app/requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): djangorestframework==2.4.4 in /opt/python/run/venv/lib/python2.6/site-packages (from -r /opt/python/ondeck/app/requirements.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): mysql-python==1.2.5 in /opt/python/run/venv/lib/python2.6/site-packages (from -r /opt/python/ondeck/app/requirements.txt (line 4))
Cleaning up...
[2014-11-26T22:56:35.097Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook/04configen.py] : Starting activity...
[2014-11-26T22:56:37.788Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook/04configen.py] : Completed activity.
[2014-11-26T22:56:37.788Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/AppDeployPreHook] : Completed activity. Result:
Successfully execute directory: /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2014-11-26T22:56:37.789Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
[2014-11-26T22:56:40.111Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Activity execution failed, because: command failed with error code 1: Error occurred during build: Command 01_migrate failed (Executor::NonZeroExitStatus)
at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:81:in `sh'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:24:in `sh'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/cfn-wrapper.rb:51:in `call_cfn_script'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/cfn-wrapper.rb:28:in `run_config_sets'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/infrahooks/infra-embeddedpostbuild.rb:20:in `execute!'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/executable.rb:56:in `instance_eval'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/executable.rb:56:in `execute!'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:213:in `block (3 levels) in exec_stage'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block in create'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `instance_eval'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `create'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:209:in `block (2 levels) in exec_stage'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:207:in `each'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:207:in `each_with_index'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:207:in `block in exec_stage'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block in create'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `instance_eval'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `create'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:204:in `exec_stage'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:158:in `execute!'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command.rb:68:in `run'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:64:in `block (2 levels) in execute!'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `call'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:169:in `exec'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:110:in `block in create'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `instance_eval'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/activity.rb:109:in `create'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:62:in `block in execute!'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:106:in `execute_command'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/lib/elasticbeanstalk/command-processor.rb:60:in `execute!'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.0/bin/command-processor:46:in `<top (required)>'
from /opt/elasticbeanstalk/lib/ruby/bin/command-processor:23:in `load'
from /opt/elasticbeanstalk/lib/ruby/bin/command-processor:23:in `<main>'
[2014-11-26T22:56:40.112Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Activity failed.
[2014-11-26T22:56:40.112Z] INFO [3842] - [CMD-AppDeploy/AppDeployStage0] : Activity failed.
[2014-11-26T22:56:40.112Z] INFO [3842] - [CMD-AppDeploy] : Completed activity. Result:
Command CMD-AppDeploy failed.
/var/log/httpd/error_log
(...)
[Wed Nov 26 22:21:56.819829 2014] [:error] [pid 2320] [client 127.0.0.1:59071] Target WSGI script not found or unable to stat: /opt/python/current/app/topdish
[Wed Nov 26 22:38:28.545144 2014] [:error] [pid 2321] [client 62.45.238.167:54585] Target WSGI script not found or unable to stat: /opt/python/current/app/topdish
[Wed Nov 26 22:38:32.716143 2014] [:error] [pid 2321] [client 62.45.238.167:54585] Target WSGI script not found or unable to stat: /opt/python/current/app/topdish
[Wed Nov 26 22:38:35.218074 2014] [:error] [pid 2321] [client 62.45.238.167:54585] Target WSGI script not found or unable to stat: /opt/python/current/app/topdish
[Wed Nov 26 22:38:39.976764 2014] [:error] [pid 2321] [client 62.45.238.167:54585] Target WSGI script not found or unable to stat: /opt/python/current/app/topdish
【问题讨论】:
您是否按照docs.aws.amazon.com/elasticbeanstalk/latest/dg/… 的说明进行操作? (您可以简化这一点,因为 AWS Elastic Beanstalk AMI 现在提供 Python 2.7) 是的,我关注了很多次。发现了一些怪癖:forums.aws.amazon.com/thread.jspa?threadID=165279&tstart=0 和 forums.aws.amazon.com/thread.jspa?threadID=166286,但现在从那里开始。仍然有这个问题:在 eb-activity.log 中找到“命令失败,错误代码 1” 虽然不是您问题的答案,但请注意,eb cli 已更新到 3.x。这是一种更好的体验,我强烈建议您升级:docs.aws.amazon.com/elasticbeanstalk/latest/dg/… 我很想看到同样失败的 cfn-init.log。我想知道您是否遇到与我相同的问题:似乎与早期 AMI 一起使用的容器命令现在因 Python 非字符串错误而失败。我的 AWS 论坛主题:forums.aws.amazon.com/message.jspa?messageID=601236#601236. 【参考方案1】:我认为'Target WSGI script not found or unable to stat: /opt/python/current/app/topdish'
错误消息是因为您的container_commands
不成功;只有在成功完成所有container_commands
之后,部署挂钩才会将应用程序从/ondeck
复制到/current
。
作为测试,请尝试在 leader_only: true
之后的新行中为您的 01_migrate
容器命令添加 ignoreErrors: true
。您的应用应该部署,但当然 syncdb 不会运行。
container_commands:
01_migrate:
command: "python manage.py syncdb --noinput"
leader_only: true
ignoreErrors: true
然后尝试输入python和manage.py的完整路径,不带ignoreErrors
:
container_commands:
01_migrate:
command: "/opt/python/run/venv/bin/python /opt/python/ondeck/app/manage.py syncdb --noinput"
leader_only: true
或者可能:
container_commands:
01_migrate:
command: "/opt/python/run/venv/bin/python26 /opt/python/ondeck/app/manage.py syncdb --noinput"
leader_only: true
【讨论】:
【参考方案2】:不幸的是,最终我同时更改了很多内容以发现实际问题。我重新创建了一个 AWS Elastic Beanstalk 应用程序,并再次尝试,现在它似乎可以工作了。
可能是 'option_settings' 之前的空白行,但不确定。
【讨论】:
你没有用这个回答你自己的问题。以上是关于无法在 Elastic Beanstalk 上部署 Django 应用程序的主要内容,如果未能解决你的问题,请参考以下文章
Elastic beanstalk [Rails] 部署问题 - 无法分配内存
无法在 Elastic Beanstalk 上部署节点:命令“/bin/sh -c npm install”返回非零代码:1
在 Elastic Beanstalk 上部署 Pyramid 应用程序