How to deploy structured Flask app on AWS elastic beanstalk

后端 未结 7 1382
猫巷女王i
猫巷女王i 2020-12-08 03:05

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

7条回答
  •  太阳男子
    2020-12-08 04:08

    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

提交回复
热议问题