Reputation: 1188
Error message in web.stdout.log:
Oct 15 13:03:29 ip-172-31-18-218 web: ModuleNotFoundError: No module named 'application'
Oct 15 13:03:29 ip-172-31-18-218 web: [2020-10-15 13:03:29 +0000] [4633] [INFO] Worker exiting (pid: 4633)
Oct 15 13:03:29 ip-172-31-18-218 web: [2020-10-15 13:03:29 +0000] [4626] [INFO] Shutting down: Master
Oct 15 13:03:29 ip-172-31-18-218 web: [2020-10-15 13:03:29 +0000] [4626] [INFO] Reason: Worker failed to boot.
Error message in nginx/error.log
2020/10/15 13:04:21 [error] 4559#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.42.151, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "172.31.18.218"
Flask app:
# EB looks for an 'application' callable by default.
application = Flask(__name__)
@application.route('/')
def home():
return "Hello World"
@application.route('/processImage')
def index():
[Some Code...]
if __name__ == '__main__':
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
application.run('localhost',8000,debug=True)
requirements.txt
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
Flask==1.1.2
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
numpy==1.19.2
opencv-python==4.4.0.44
requests==2.24.0
urllib3==1.25.10
Werkzeug==1.0.1
My folder structure:
eb-flask
|- .vscode (folder)
|- images (folder)
|- application.py
|- requirements.txt
Way of deployment:
Deployment via the Elastic Beanstalk Web UI by uploading a .zip archive of the above described folder.
Any ideas on how to further debug or solve this would be highly appreciated. Thanks a lot in advance.
Upvotes: 3
Views: 1636
Reputation: 21
I was getting the same error.
Few things I did was:
application = app = Flask(__name__)
.application.py
.Also very important: whatever files are required select those and zip them (right-click "send to" -> "compressed" in windows) and upload to the beanstalk.
DO NOT put all the required files in a folder and zip. This was the reason behind ModuleNotFound: No Module name 'application'
.
Upvotes: 2
Reputation: 238051
You are running your application on port 8000. However, EB will expect it on port 5000. So either you change the default port on the EB, your you modify your application to run on port 5000:
application.run('localhost', 5000,debug=True)
Upvotes: 1
Reputation: 2422
You might need to add the modules to the environments path variable so that the module lookup is sucessful. Run the following from a file/ command line-
import sys
import os
sys.path.append("/path_to_your_app/eb-flask")
Upvotes: 0