[英]Deploying Flask App in AWS Elastic Beanstalk
when I deploy my flask app, it says successful but when I retrieve the logs, I see the error "Flask not found".当我部署我的 Flask 应用程序时,它说成功,但是当我检索日志时,我看到错误“找不到 Flask”。 I have flask in my requirements file.我的需求文件中有烧瓶。 Any help.任何帮助。
[Sat Jan 11 06:51:50.503908 2020] [:error] [pid 3393] [remote 127.0.0.1:0] mod_wsgi (pid=3393): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module. [Sat Jan 11 06:51:50.503908 2020] [:error] [pid 3393] [remote 127.0.0.1:0] mod_wsgi (pid=3393):目标 WSGI 脚本'/opt/python/current/app/application.py ' 不能作为 Python 模块加载。
[Sat Jan 11 06:51:50.503953 2020] [:error] [pid 3393] [remote 127.0.0.1:0] mod_wsgi (pid=3393): Exception occurred processing WSGI script '/opt/python/current/app/application.py'. [Sat Jan 11 06:51:50.503953 2020] [:error] [pid 3393] [remote 127.0.0.1:0] mod_wsgi (pid=3393):处理 WSGI 脚本'/opt/python/current/app/application 时发生异常.py'。
[Sat Jan 11 06:51:50.504123 2020] [:error] [pid 3393] [remote 127.0.0.1:0] Traceback (most recent call last): [Sat Jan 11 06:51:50.504151 2020] [:error] [pid 3393] [remote 127.0.0.1:0] File "/opt/python/current/app/application.py", line 1, in [Sat Jan 11 06:51:50.504156 2020] [:error] [pid 3393] [remote 127.0.0.1:0] from flask import Flask [Sat Jan 11 06:51:50.504123 2020] [:error] [pid 3393] [remote 127.0.0.1:0] Traceback(最近一次通话):[Sat Jan 11 06:51:50.504151:2020] [错误] [pid 3393] [远程 127.0.0.1:0] 文件“/opt/python/current/app/application.py”,第 1 行,在 [Sat Jan 11 06:51:50.504156 2020] [:error] [pid 3393 ] [远程 127.0.0.1:0] 从烧瓶进口烧瓶
[Sat Jan 11 06:51:50.504170 2020] [:error] [pid 3393] [remote 127.0.0.1:0] ModuleNotFoundError: No module named 'flask'. [Sat Jan 11 06:51:50.504170 2020] [:error] [pid 3393] [remote 127.0.0.1:0] ModuleNotFoundError:没有名为“flask”的模块。
Below is my application.py content下面是我的 application.py 内容
from flask import Flask
from myapp import create_app
application = create_app()
if __name__ == "__main__":
application.run()
Below is the content of my requirements.txt下面是我的requirements.txt的内容
Click==7.0
-e git+https://github.com/xxxxxx/xxx.git@xxxx#egg=xxx
Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
numpy==1.18.1
PyYAML==3.13
scipy==1.4.1
Werkzeug==0.16.0
can you try renaming the Flask object that you run to 'application':您可以尝试将运行的 Flask 对象重命名为“应用程序”:
from flask import Flask
application = Flask(__name__)
# run the app.
if __name__ == "__main__":
application.run()
From the Amazon EB Docs:来自亚马逊 EB 文档:
Using application.py as the filename and providing a callable application object (the Flask object, in this case) allows AWS Elastic Beanstalk to easily find your application's code.使用 application.py 作为文件名并提供可调用的应用程序对象(在本例中为 Flask 对象)允许 AWS Elastic Beanstalk 轻松找到您的应用程序代码。
You should have application.py
and the requirements.txt
at the root of the folder.您应该在文件夹的根目录下有application.py
和requirements.txt
。 Your deployed zip file also should contain these two files at the root of the zip file.您部署的 zip 文件还应在 zip 文件的根目录中包含这两个文件。 I have attached the reference shows how to download a deployed application bundle.我附上了参考资料,展示了如何下载已部署的应用程序包。
Reference: Download a application from AWS Elastic Beanstalk参考: 从 AWS Elastic Beanstalk 下载应用程序
hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.