Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

python - How to deploy structured Flask app on AWS elastic beanstalk

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...