If you see the following error:
ERROR: Your WSGIPath refers to a file that does not exist.
Note the following:
- EC2 (server) instances in EB (platform) run Apache.
- Apache finds Python apps according to our WSGIPATH.
- By default EB assumes the WSGI file is called application.py.
There are two ways of correcting this.
Option 1: Using environment-specific configuration settings
Run: $ eb config
Find the following config file “.elasticbeanstalk/src-test.env.yml.”
This file doesn’t actually exist locally; EB pulled it so that you can edit it.
If you save changes in this pseudo-file, EB will update the corresponding settings in your env.
If you search for the terms ‘WSGI’ in the file, you should find a config section resembling this:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: application.py
Update the WSGIPath:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: src/src/wsgi.py #src/src is an example. Do not just c&p.
If you save the file, EB will update the env config automatically.
The advantage to using the $ eb config
method to change settings is that you can specify different settings per env.
Option 2: Using global configuration settings
To use this option, create a new file called /.ebextensions/02_python.config:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: “src.settings" #src is an example.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" #src is an example.
"aws:elasticbeanstalk:container:python":
WSGIPath: src/src/wsgi.py #src is an example.
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
What’s happening?
DJANGO_SETTINGS_MODULE: "src.settings" - adds the path to the settings module.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" - updates our PYTHONPATH so Python can find the modules in our application.(Note that the use of the full path is necessary.)
WSGIPath: src/src/wsgi.py sets our WSGI Path.
NumProcesses: 3 and NumThreads: 20 - updates the number of processes and threads used to run our WSGI application.
"/static/": "www/static/" sets our static files path.
Run $ git commit
(if necessary) and $ eb deploy
to update these settings.