在主模块的__init__.py
文件中获得了一个Flask应用程序,该应用程序具有Flaskapplication
初始化,与这里的Flask文档非常相似(除了我不是使用应用程序工厂类型函数(
myapp/
myapp/
__init__.py # application = Flask(__name__) is here
static/
templates/
...
requirements.txt
当FLASK_APP
设置为myapp
时,本地环境使用flask run
运行良好。
我对Beanstalk部署的尝试是通过eb-cli
进行的,并且我在.ebextensions/options.yml
中设置了FLASK_APP
,如下所示:
option_settings:
aws:elasticbeanstalk:application:environment:
LC_ALL: en_US.utf8
FLASK_APP: myapp
FLASK_ENV: production
然后我运行:
eb init -p python-3.7 myapp --region us-east-1
eb create myapp-env
它似乎启动得很好,但环境变差了,我得到了502,日志显示由于No module named 'application'
,Flask应用程序没有正确启动
我的印象是,设置FLASK_APP
就足以定位Flask应用程序实例。
在这种情况下,我如何通过Elastic Beanstalk部署Flask应用程序?我是否需要以某种方式进一步指定入口点?
基于注释。
该问题是由使用自定义烧瓶应用程序路径引起的。默认情况下,EB希望应用程序位于application.py
文件中。
解决方案是在aws:elasticbeanstall:container:python option:中使用WSGIPath
指定自定义路径
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: myapp:application