简体   繁体   English

如何在AWS Elastic Beanstalk上部署Flask与运行脚本不同?

[英]How is Deploying Flask on AWS Elastic Beanstalk different from running script?

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? 在ec2实例上部署Flask应用程序(换句话说,在任何计算机上运行脚本)和通过AWS Elastic Beanstalk部署Flask应用程序有什么区别? The Flask deployment documentation says that: 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. 虽然重量轻且易于使用,但Flask的内置服务器不适合生产,因为它不能很好地扩展,默认情况下一次只能提供一个请求。 Some of the options available for properly running Flask in production are documented here. 此处记录了可用于在生产中正确运行Flask的一些选项。

One of the deployment options they recommend is AWS Elastic Beanstalk. 他们推荐的部署选项之一是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. 然而,当我阅读亚马逊关于如何部署Flask应用程序的解释时,似乎他们正在使用与Flask内置的完全相同的服务器应用程序,例如,它是单线程的,因此无法处理同时发出的请求。 I understand that Elastic Beanstalk allows you to deploy multiple copies, but it still seems to use the built-in Flask server application. 据我所知,Elastic Beanstalk允许您部署多个副本,但它似乎仍然使用内置的Flask服务器应用程序。 What am I missing? 我错过了什么?

TL;DR Completely different - Elastic Beanstalk does use a sensible WSGI runner that's better than the Flask dev server! TL; DR完全不同 - Elastic Beanstalk 确实使用了比Flask开发服务器更好的WSGI运行器!

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 然而,当我阅读亚马逊关于如何部署Flask应用程序的解释时,他们似乎正在使用与Flask内置的完全相同的服务器应用程序

Almost, but not quite. 几乎,但不完全。

You can confirm that this isn't the case by removing the run-with-built-in-server section yourself - ie the following from the example: 您可以通过自行删除run-with-built-in-server部分来确认不是这种情况 - 即示例中的以下内容:

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()

You'll stop being able to run it yourself locally with python application.py but it'll still happily run on EB! 你将无法使用python application.py在本地运行它,但它仍然可以在EB上运行!

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: EB Python平台使用自己的WSGI服务器(带有mod_wsgi的Apache,我看过的最后一个)和一些假设/配置来查找你的WSGI可调用:

From Configuring a Python project for Elastic Beanstalk : 为Elastic Beanstalk配置Python项目

By default, Elastic Beanstalk looks for a file called application.py to start your application. 默认情况下,Elastic Beanstalk会查找名为application.py的文件来启动您的应用程序。 If this doesn't exist in the Python project that you've created, some adjustment of your application's environment is necessary. 如果在您创建的Python项目中不存在这种情况,则需要对应用程序的环境进行一些调整。

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: 如果你查看了aws:elasticbeanstalk:container:python命名空间的文档,你会看到你可以配置它来寻找你的WSGI应用程序的其他地方:

WSGIPath : The file that contains the WSGI application. WSGIPath :包含WSGI应用程序的文件。 This file must have an "application" callable. 此文件必须具有“应用程序”可调用。 Default: application.py 默认值: application.py

Elastic compute resources (AWS and others) generally allow for dynamic load balancing, and start more compute resources as they are needed. 弹性计算资源(AWS和其他)通常允许动态负载平衡,并在需要时启动更多计算资源。

If you deploy on a single ec2 instance, and this instance reaches capacity, your users will experience poor performance. 如果部署在单个ec2实例上,并且此实例达到容量,则用户将遇到性能不佳的情况。 If you deploy elastically, new resources are dynamically added as to ensure smooth performance. 如果弹性部署,则会动态添加新资源,以确保顺畅的性能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM