How to deploy structured Flask app on AWS elastic beanstalk

Viewed 19193

After successfully deploying a test app using the steps outlined here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_flask.html

I tried to deploy my actual flask application which has the following structure:

myApp/
   runServer.py
   requirements.txt
   myApp/
      __init__.py
      helpers.py
      clean.sh
      static/
         myApp.css
      handlers/
         __init__.py
         views.py
      templates/
         layout.html
         viewOne.html
         viewTwo.html

Where views.py contains my url mappings.

I have tried initializing the eb instance in the root directory as well as within the myApp module and git aws.push but I get the following error on the AWS dashboard: ERROR Your WSGIPath refers to a file that does not exist. and the application does not work (404 for any path).

How can I deploy the above Flask application to elastic beanstalk?

7 Answers

WSGI configuration was painful for me. I did changed WSCI settings using eb config command but it did not work. Below you can fix this in 5 easy steps.

1- Moved app.py function to the root of the directory (where I runned eb init command.

2- Also renamed app.py as application.py and in that initilized application as application = Flask(__name__) not app = Flask(__name__)

3- eb deploy did not worked after this (in the same project) I tried to fix config by using eb config but it was too hairy to sort it out. Delete all .extensions, .gitignore etc from your project.

4- re initialize your project on EB with eb init and follow the prompts. when deployment is done, eb open would launch your webapp (hopefully!)

Well, In my case I followed the entire process and conventions but was still getting 404. The problem was my virtual environment. I was ignoring all environment config related folders/files in my .gitignore but not in .ebignore. After creating .ebignore and ignoring all the folders/files which were not related to project code, fixed the issue.

Related