How to deploy structured Flask app on AWS elastic beanstalk

I encountered a similar problem deploying a Flask application to EB, with a similar directory structure, and had to do 2 things:

  1. Update my manage.py to create an object of name application, not app

    import os
    from application import create_app, db
    from flask.ext.script import Manager, Shell
    
    application = create_app(os.getenv('FLASK_CONFIG') or 'default')
    manager = Manager(application)
    
  2. Create .ebextensions/myapp.config, and define the following block to point to manage.py

    option_settings:
      "aws:elasticbeanstalk:container:python":
        WSGIPath: manage.py
      "aws:elasticbeanstalk:container:python:staticfiles":
        "/static/": "application/static/" 
    

This let Elastic Beanstalk find the application callable correctly.

This is described briefly at the official docs, and is described in more detail in this blog post

EDIT - see project structure below

  • ProjectRoot
    • .ebextensions
      • application.config
    • application
      • main
        • forms.py
        • views.py
    • static
    • templates
    • tests
    • manage.py
    • requirements.txt
    • config.py
    • etc, etc

Add the following to .ebextensions/<env-name>.config:

option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: myApp/handlers/views.py

Update:

If you don't have .ebextensions directory, please create one for the project. You can find more information of what can be done regarding the container configuration in Customizing and Configuring AWS Elastic Beanstalk Environments guide.


Your WSGIPath refers to a file that does not exist.

This error appears because Beanstalk, by default, looks for application.py. Check at Beanstalk web UI, Configuration > Software Configuration, WSGIPath is mapped to application.py

WSGIPath is set by default to application.py. Set to manage.py.

Update the WSGIPath as shown in the previous replies or rename to application.py file.