简体   繁体   English

如何在 AWS Elastic Beanstalk 上配置我的 WSGI 应用程序的名称?

[英]How do I configure the name of my WSGI application on AWS Elastic Beanstalk?

My Python web application is called app我的 Python Web 应用程序称为app

# example.py
import flask

app = flask.Flask(__name__.split('.')[0])

and when I attempt to launch it on AWS-EB using当我尝试使用 AWS-EB 在 AWS-EB 上启动它时

# run.py (set correctly with WSGIPath)
from example import app

if __name__ == "__main__":
    app.run()

I get我得到

mod_wsgi (pid=22473): Target WSGI script '/opt/python/current/app/run.py' 
    does not contain WSGI application 'application'.

How to I tell AWS that my application instance is called app ?如何告诉 AWS 我的应用程序实例名为app

mod_wsgi expects variable called application . mod_wsgi 需要名为application变量。 Try to do something like this尝试做这样的事情

from example import app as application

Note: don't do application.run() .注意:不要做application.run() It is not needed.不需要。

While the WSGIPath can be configured.虽然可以配置 WSGIPath。 Beanstalk still expects the app variable to be named as 'application'. Beanstalk 仍然希望 app 变量被命名为“application”。

A simple workaround for small single file python apps can be小型单文件 python 应用程序的简单解决方法可以是

from flask import Flask

app = Flask(__name__)
application = app # For beanstalk

You can keep the rest of the code as is.您可以保留其余代码原样。 You just need to add that single line application = app您只需要添加单行application = app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 AWS Deep Learning Base AMI (Amazon Linux 2) 时,如何在 Elastic Beanstalk 中设置 WSGI? - How do I set up WSGI in Elastic Beanstalk when running AWS Deep Learning Base AMI (Amazon Linux 2)? 不使用WSGI在AWS Elastic Beanstalk上部署Tornado - Deploying Tornado on AWS Elastic Beanstalk without WSGI 如何在 AWS Elastic Beanstalk 上强制应用程序版本 - How to force application version on AWS Elastic Beanstalk AWS Elastic Beanstalk Python:如何配置环境以使用硒? - AWS Elastic Beanstalk Python: How to configure the environment to use selenium? Amazon Elastic Beanstalk:如何设置 wsgi 路径? - Amazon Elastic Beanstalk : how to set the wsgi path? Django AWS Elastic-Beanstalk WSGI.py配置 - Django AWS Elastic-Beanstalk WSGI.py configuration 如何使用应用程序工厂将Flask应用程序部署到AWS Elastic beantalk - How to deploy Flask app to AWS Elastic beanstalk using an application factory 如何在AWS Elastic-Beanstalk中更改我的python版本 - How to change my python version in AWS elastic-beanstalk 更新 AWS Elastic Beanstalk 解决方案堆栈名称 - Update AWS Elastic Beanstalk solution stack name 如何从Jenkins将Python应用程序部署到Amazon Elastic Beanstalk? - How do I deploy a Python application to Amazon Elastic Beanstalk from Jenkins?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM