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:
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.
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 Completely different: Elastic Beanstalk uses a sensible WSGI broker that is better than the Flask development server!
However, when I read Amazon's explanation of how to deploy a Flask app, it sounds like they're using the exact same server app that comes built into Flask.
Almost, but not quite.
You can confirm that this is not the case by removing the run with embedded 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() You will no longer be able to run it yourself locally with python application.py , but it will still run happily in EB!
The EB Python platform uses its own WSGI server (Apache with mod_wsgi, last I looked) and a few guesses/settings to find its WSGI callable:
From Setting up a Python project for Elastic Beanstalk :
By default, Elastic Beanstalk looks for a file named application.py to launch your application. If this doesn't exist in the Python project you created, some adjustments to your application environment are required.
If you look at the docs for the aws:elasticbeanstalk:container:python , you'll see that you can configure it to look for your WSGI application elsewhere:
WSGIPath– The file that contains the WSGI application. This file must have a callable "application". Default:application.py
Elastic compute resources (AWS and others) generally allow for dynamic load balancing, and start more compute resources as they are needed.
If you deploy on a single ec2 instance, and this instance reaches capacity, your users will experience poor performance. If you deploy elastically, new resources are dynamically added as to ensure smooth performance.