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?
This error appears because Beanstalk, by default, looks for application.py. Check at Beanstalk web UI,
Configuration > Software Configuration
,WSGIPath
is mapped toapplication.py
Update the
WSGIPath
as shown in the previous replies or rename toapplication.py
file.I encountered a similar problem deploying a Flask application to EB, with a similar directory structure, and had to do 2 things:
Update my manage.py to create an object of name application, not app
Create
.ebextensions/myapp.config
, and define the following block to point to manage.pyThis 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
As of awsebcli 3.0, you can actually edit your configuration settings to represent your
WSGI
path viaeb config
. Theconfig
command will then pull (and open it in your default command line text editor, i.e nano) an editable config based on your current configuration settings. You'll then search forWSGI
and update it's path that way. After saving the file and exiting, yourWSGI
path will be updated automatically.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 runnedeb init
command.2- Also renamed
app.py
asapplication.py
and in that initilized application asapplication = Flask(__name__)
notapp = Flask(__name__)
3-
eb deploy
did not worked after this (in the same project) I tried to fix config by usingeb 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!)When I encountered this problem it was because I was using the GUI to upload a zip of my project files. Initially I was uploading a zip of the project directory and got this error.
Then I switched to simply uploading zip of the project files themselves-ie select all files and send those to a zip-and then the GUI upload utility was able to find my application.py file without a problem.
Add the following to
.ebextensions/<env-name>.config
: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.