在AWS Elastic Beanstalk上部署Flask与运行脚本有何不同? [英] How is Deploying Flask on AWS Elastic Beanstalk different from running script?

查看:92
本文介绍了在AWS Elastic Beanstalk上部署Flask与运行脚本有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ec2实例上部署Flask应用程序(换句话说,在任何计算机上运行脚本)与通过AWS Elastic Beanstalk部署Flask应用程序之间有什么区别? Flask 部署文档表示:

What is the difference between deploying a Flask application on an ec2 instance (in other words running your script on any computer) and deploying a Flask application via AWS Elastic Beanstalk? The Flask deployment documentation says that:


虽然轻巧易用,但Flask的内置服务器不适用于生产环境,因为它的伸缩性不好,并且默认情况下,仅服务一个请求即可满足
的需求一次。此处记录了在生产中正确运行Flask的
可用的一些选项。

While lightweight and easy to use, Flask’s built-in server is not suitable for production as it doesn’t scale well and by default serves only one request at a time. Some of the options available for properly running Flask in production are documented here.

他们推荐的部署选项之一是AWS Elastic Beanstalk。当我阅读亚马逊的解释时,如何部署Flask应用程序,但是,它们似乎使用与Flask内置的服务器应用程序完全相同的服务器应用程序,例如单线程,因此无法处理并发请求。我了解到,Elastic Beanstalk允许您部署多个副本,但是它似乎仍然使用内置的Flask服务器应用程序。我缺少什么?

One of the deployment options they recommend is AWS Elastic Beanstalk. When I read through Amazon's explanation of how to deploy a Flask app, however, it seems like they are using the exact same server application as comes built-in to Flask, which for example is single threaded and so cannot handle simultaneous requests. I understand that Elastic Beanstalk allows you to deploy multiple copies, but it still seems to use the built-in Flask server application. What am I missing?

推荐答案

TL; DR完全不同-Elastic Beanstalk 确实使用了明智的WSGI

TL;DR Completely different - Elastic Beanstalk does use a sensible WSGI runner that's better than the Flask dev server!


但是,当我通读亚马逊关于如何部署Flask应用程序的解释时,似乎他们正在使用与Flask内建的服务器应用程序完全相同的服务器

When I read through Amazon's explanation of how to deploy a Flask app, however, it seems like they are using the exact same server application as comes built-in to Flask

几乎,但不完全是。

您可以通过自己删除服务器内部运行部分来确认是否为 ,例如示例中的以下内容:

You can confirm that this isn't the case by removing the run-with-built-in-server section yourself - i.e. the following from the example:

if __name__ == "__main__":
    # Setting debug to True enables debug output. This line should be
    # removed before deploying a production app.
    application.debug = True
    application.run()

您将不再能够使用 python application.py 在本地运行它,但是它仍然可以在EB上愉快地运行!

You'll stop being able to run it yourself locally with python application.py but it'll still happily run on EB!

EB Python平台使用其自己的WSGI服务器(带有最后一个Apache的mod_wsgi)和一些假设/配置来查找可调用的WSGI:

The EB Python platform uses its own WSGI server (Apache with mod_wsgi, last I looked) and some assumptions / config to find your WSGI callable:

来自为Elastic Beanstalk配置Python项目


默认情况下,Elastic Beanstalk查找一个名为application.py的文件以启动您的应用程序。如果您创建的Python项目中不存在此功能,则必须对应用程序的环境进行一些调整。

By default, Elastic Beanstalk looks for a file called application.py to start your application. If this doesn't exist in the Python project that you've created, some adjustment of your application's environment is necessary.

请查看 aws:elasticbeanstalk:container:python 命名空间,您会看到可以对其进行配置以在其他地方为您的WSGI应用程序查找:

If you check out the docs for the aws:elasticbeanstalk:container:python namespace you'll see you can configure it to look elsewhere for your WSGI application:


WSGIPath :包含WSGI应用程序的文件。该文件必须具有可调用的应用程序。默认值: application.py

WSGIPath: The file that contains the WSGI application. This file must have an "application" callable. Default: application.py

这篇关于在AWS Elastic Beanstalk上部署Flask与运行脚本有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆