Setting up Django on AWS Elastic Beanstalk: WSGIPath not found

19,194

Solution 1

From https://forums.aws.amazon.com/thread.jspa?messageID=396656&#396656

The ".ebextensions" directory must be in the root level directory of your application, but from the log output, the directory is instead in the "mysite/.ebextensions" directory. So for example, after following the django tutorial in the docs when you run "git aws.push" your root directory would look like this:

.
├── .ebextensions
│   └── python.config
├── .elasticbeanstalk
│   ├── config
├── .git
├── .gitignore
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── requirements.txt

Instead of this:

.
└── mysite
    ├── .ebextensions
    ├── .elasticbeanstalk
    ├── .git
    ├── .gitignore
    ├── manage.py
    ├── mysite
    └── requirements.txt

Solution 2

Find .elasticbeanstalk/optionsettings.your-app-name in your app's root directory. Search for WSGIPath and make sure it's the path you intend. It looks like it defaults to application.py.

Solution 3

I had the same problem ("Your WSGIPath refers to a file that does not exist"), and finally found a solution:

Note: At first, I was searching in the wrong direction, because EB was also showing this message: Error occurred during build: Command 01_migrate failed.. So I though the files, including the *.config, were correctly located.

Solution 4

Solution: using EBCLI

open eb config For me it showed WSGIPath: application.py Now Change it to

WSGIPath: my_app/wsgi.py

save and deploy.

Solution 5

Ok, here's what worked for me after trying a million things. You have to run eb update in order to update the environment.

So make sure .elasticbeanstalk/optionsettings.whatever-env has WSGIPath set to what you want it, and make sure .ebextensions/whatever.config has this:

option_settings:
  - namespace: aws:elasticbeanstalk:container:python
    option_name: WSGIPath
    value: whatever/wsgi.py

Then run eb update and it should work. Remember you have to set the alias to make sure your eb command actually works. For example:

alias eb="python2.7 ../AWS-ElasticBeanstalk-CLI-2.6.3/eb/linux/python2.7/eb"
Share:
19,194
Xephryous
Author by

Xephryous

Updated on June 15, 2022

Comments

  • Xephryous
    Xephryous about 2 years

    I've been trying for several days now to set up Django under Amazon Web Services' Elastic Beanstalk. I think the problem I'm hitting is this one:

    ERROR - Your WSGIPath refers to a file that does not exist.
    

    I followed the tutorial here and all goes well until the end of Step 6, but I can't for the life of me get anything to display other than the generic Elastic Beanstalk page from Step 5, #2. When I run

    ./manage.py runserver
    

    on my local machine, everything works as it should, but I can't get that page to deploy. I first tried with a small Django site I wrote myself. It didn't work, so I deleted everything I'd done and tried again, that didn't work, so I deleted all that and tried again with a fresh django install. I tried that a bunch of times fiddling with little things, but I think I'm missing something major.

    I added a python.config file as described in this tutorial.

    Here's my file structure:

    -.git/
    -.mysite/
        -myapp/
            -__init__.py
            -models.py
            -tests.py
            -views.py
        -mysite/
            -__init__.py
            -settings.py
            -urls.py
            -wsgi.py
        -.ebextensions/
            -python.config
        -manage.py
        -mysite.db
        -requirements.txt
    

    From my settings.py:

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': 'mysite.db',
            'USER': '',
            'PASSWORD': '',
            'HOST': '',
            'PORT': '',
        }
    }
    

    Here's python.config:

    container_commands:   01_syncdb:    
        command: "django-admin.py syncdb --noinput"
        leader_only: true
    
    option_settings:
        - namespace: aws:elasticbeanstalk:container:python
          option_name: WSGIPath
          value: mysite/wsgi.py
        - option_name: DJANGO_SETTINGS_MODULE
          value: mysite.settings
        - option_name: AWS_SECRET_KEY
          value: <This is my secret key>
        - option_name: AWS_ACCESS_KEY_ID
          value: <This is my access key>
    

    Is there another place I need to define my WSGIPath? Is there a way to do it through the AWS console? Should I just skip EB altogether and use EC2 directly?