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?
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.
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
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)
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
As of awsebcli 3.0, you can actually edit your configuration settings to represent your WSGI
path via eb config
. The config
command will then pull (and open it in your default command line text editor, ie nano) an editable config based on your current configuration settings. You'll then search for WSGI
and update it's path that way. After saving the file and exiting, your WSGI
path will be updated automatically.
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
Update the WSGIPath
as shown in the previous replies or rename to application.py
file.
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!)
When I encountered this problem it was because I was using the GUI to upload a zip of my project files. Initially I was zipping the project level directory and uploading that zip to EB.
Then I switched to simply uploading a 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 because the application.py file was not in a subfolder.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.