简体   繁体   中英

Deploying Flask App in AWS Elastic Beanstalk

when I deploy my flask app, it says successful but when I retrieve the logs, I see the error "Flask not found". I have flask in my requirements file. Any help.

[Sat Jan 11 06:51:50.503908 2020] [:error] [pid 3393] [remote 127.0.0.1:0] mod_wsgi (pid=3393): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.

[Sat Jan 11 06:51:50.503953 2020] [:error] [pid 3393] [remote 127.0.0.1:0] mod_wsgi (pid=3393): Exception occurred processing WSGI script '/opt/python/current/app/application.py'.

[Sat Jan 11 06:51:50.504123 2020] [:error] [pid 3393] [remote 127.0.0.1:0] Traceback (most recent call last): [Sat Jan 11 06:51:50.504151 2020] [:error] [pid 3393] [remote 127.0.0.1:0] File "/opt/python/current/app/application.py", line 1, in [Sat Jan 11 06:51:50.504156 2020] [:error] [pid 3393] [remote 127.0.0.1:0] from flask import Flask

[Sat Jan 11 06:51:50.504170 2020] [:error] [pid 3393] [remote 127.0.0.1:0] ModuleNotFoundError: No module named 'flask'.

Below is my application.py content

from flask import Flask
from myapp import create_app

application = create_app()

if __name__ == "__main__":
    application.run()

Below is the content of my requirements.txt

Click==7.0
-e git+https://github.com/xxxxxx/xxx.git@xxxx#egg=xxx
Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
numpy==1.18.1
PyYAML==3.13
scipy==1.4.1
Werkzeug==0.16.0

can you try renaming the Flask object that you run to 'application':

from flask import Flask
application = Flask(__name__)
# run the app.
if __name__ == "__main__":
    application.run()

From the Amazon EB Docs:

Using application.py as the filename and providing a callable application object (the Flask object, in this case) allows AWS Elastic Beanstalk to easily find your application's code.

You should have application.py and the requirements.txt at the root of the folder. Your deployed zip file also should contain these two files at the root of the zip file. I have attached the reference shows how to download a deployed application bundle.

Reference: Download a application from AWS Elastic Beanstalk

hope this helps.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM