I've been trying to figure out this problem for a while but can't figure it out. My app structure is like this:
myapp
-application.py
-myapp
-sample.css
-sample.js
-blueprints.py
-__init__.py
-__init__.pyc
-templates
-base.jinja2
-node_modules
-package.json
-requirements.txt
-static
-venv
-webpack.config.js
I have python 2.7 environment for beanstalk and the same for my virtual environment. I have all the needed packages in pip list and requirements.txt. My WSGI path in the yml file from eb config is set to /myapp/application.py. The exact error I get from eb logs is:
mod_wsgi (pid=2330): Target WSGI script '/opt/python/current/app/myapp/application.py' cannot be loaded as Python module.
mod_wsgi (pid=2330): Exception occurred processing WSGI script '/opt/python/current/app/myapp/application.py'.
"File "/opt/python/current/app/cloud-dev/application.py", line 3, in <module>
from flask import render_template
ImportError: No module named flask"
I keep getting a 500 error when going to the site link. Help is much appreciated!
To deploy a Flask app to AWS Elastic Beanstalk, you need to do the following in order: Create your Flask app & provide Python dependencies: This will be your code that will be deployed to AWS Elastic Beanstalk along with requirements. txt. Zip your app: Zip all of your source code and dependencies into a single file.
Elastic Beanstalk isn't great if you need a lot of environment variables. The simple reason is that Elastic Beanstalk has a hard limit of 4KB to store all key-value pairs. The environment had accumulated 74 environment variables — a few of them had exceedingly verbose names.
I encountered the exact same error. What helped for me is 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With