2

Got a Flask app that has the Flask application initialization in the main module's __init__.py file, much like the Flask docs has here (except I'm not using an app factory type function)

myapp/
  myapp/
    __init__.py  # application = Flask(__name__) is here
    static/
    templates/
    ...
  requirements.txt

Local environment runs fine with flask run when FLASK_APP is set to myapp.

My attempt with the Beanstalk deployment is via eb-cli and I have the FLASK_APP set in .ebextensions/options.yml like so:

option_settings:
 aws:elasticbeanstalk:application:environment:
   LC_ALL: en_US.utf8
   FLASK_APP: myapp
   FLASK_ENV: production

Then I'm running:

eb init -p python-3.7 myapp --region us-east-1
eb create myapp-env

It seems to launch fine, but the environment becomes degraded, I get a 502 and the logs show that the Flask app does not launch correctly due to No module named 'application'

I was under the impression that setting FLASK_APP would be enough to locate the Flask app instance.

How do I deploy a Flask app via Elastic Beanstalk in this context? Do I need to further specify the entry-point somehow?

5
  • I think you have to customize WSGIPath as your application is not application.py. You can use aws:elasticbeanstalk:container:python in order to do so. Commented Sep 21, 2020 at 22:58
  • Any idea what that should look like exactly? I'm trying it with WSGIPath: application. Commented Sep 21, 2020 at 23:03
  • I would start with renaming/refactoring your code (if possible) to use application.py instead of __init_.py, to confirm that this is actually the issue. application.py should be in root of your folder, not subfolders. Also .ebextensions/options.yml is incorrect. The extension should be .config. If you confirm this, then you know where to concentrate the efforts to solve the issue. Not sure how to use __init__.py. Would have to try-and-see how to use it in WSGIPath. Commented Sep 21, 2020 at 23:09
  • 1
    The answer is WSGIPath: myapp:application. You want to put this as an answer? I'll mark it correct. Commented Sep 21, 2020 at 23:36
  • Thank you. Yes, I would like to provide an answer :-) Commented Sep 21, 2020 at 23:37

1 Answer 1

2

Based on the comments.

The issue was caused by using custom flask application path. By default, EB expects the application to be located in application.py file.

To solution was to specify the custom path using WSGIPath in aws:elasticbeanstalk:container:python option:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: myapp:application
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.