17

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?

0

2 Answers 2

16

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

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

Almost, but not quite.

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

You'll stop being able to run it yourself locally with python application.py but it'll still happily run on 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:

From Configuring a Python project for Elastic Beanstalk:

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.

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: The file that contains the WSGI application. This file must have an "application" callable. Default: application.py

Sign up to request clarification or add additional context in comments.

2 Comments

Once I got it going I saw that the interface panel says it has a threaded WSGI, though I don't see where it says which one it uses. Do you have any documentation to point to for "Apache with mod_wsgi, last I looked" ?
From docs.aws.amazon.com/elasticbeanstalk/latest/dg/… - "an Apache proxy server with WSGI". I'm not able to spin up an instance to actually poke it right now to check for mod_wsgi though!
-5

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.

1 Comment

All of that makes sense. However, that would still seem to suggest that you should deploy Flask wrapped in one of the server applications suggested on the Flask deployment page so that each individual instance deployed by Elastic Beanstalk is more efficient. My question is basically isn't Amazon telling you to do what Flask tells you not to do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.