Setting up Django on AWS Elastic Beanstalk: WSGIPath not found
Asked Answered
N

6

29

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?

Najera answered 27/10, 2012 at 16:40 Comment(3)
This issue has been solved as detailed here. I was storing all of the code in one directory, and I zipped (and uploaded) that whole directory. What I should have done was zipped all of the relevant files IN that directory rather than the directory itself, so when unzipped the files will all be in the site's root directory. Hope this helps someone else with the same problem. I think I ran into the same issue uploading via the GUI and via git.Najera
You should not edit the question but add your own answer and accept it.Expatiate
Please take into account that uncommitted changes are not going to be deployed, so you should have all your changes on ".ebextensions" folder committed in order to deploy it with EB CLI.Acetify
E
14

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
Esbenshade answered 17/2, 2013 at 21:12 Comment(2)
That's the one! I actually answered my own question in a comment here. I think I didn't have enough SO reputation to reply at the time or something. Anyways, the issue is resolved.Najera
We had a problem with psycopg2 not installed. adding those lines to our .ebextensions/01-app.config file fixed it: packages: yum: postgresql93-devel: []Suannesuarez
A
8

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.

Alcohol answered 17/7, 2013 at 23:4 Comment(1)
What is the path relative to? Also the eb script seems to keep overwriting the value I put in there.Declination
P
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.

Pervade answered 24/3, 2015 at 15:17 Comment(0)
R
3

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.

Racket answered 8/2, 2019 at 9:51 Comment(2)
Refer this #31169760Racket
this is the only solution that worked for me even with their documentation example: docs.aws.amazon.com/elasticbeanstalk/latest/dg/… "If you're using an Amazon Linux AMI Python platform version (preceding Amazon Linux 2), replace the value for WSGIPath with ebdjango/wsgi.py. The value in the example works with the Gunicorn WSGI server, which isn't supported on Amazon Linux AMI platform versions." <-- is confusing because well I'm using current Amazon Linux 2. Is this a bug in their documentation?Cluny
C
2

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"
Contrapose answered 5/7, 2014 at 4:5 Comment(1)
I believe eb update has changed to eb deploy recently. This could be useful for people looking for this kind of information in 2016 :)Strake
T
2

I had the same issue after following AWS's docs to the dot. What I did to avoid it was initialize an application through the EB CLI step by step, without using the command the AWS docs instructed (~/ebdjango$ eb init -p python2.7 django-tutorial), and creating an environment step by step as well. The steps I took in the EB CLI are the following:

  1. Initialize Application
    1. eb init
    2. Select a default region
    3. Enter Application Name (used default by pressing enter)
    4. Confirmed that I am using Python
    5. Selected Python version compatible with my local environment
    6. Set up SSH
  2. Create Environment
    1. eb create
    2. Enter Environment Name (used default by pressing enter)
    3. Enter DNS CNAME prefix (used default by pressing enter)
    4. Select a load balancer type (I selected classic by entering 1)

After Environment is created I use eb config to open EB's config file to confirm that the path to my WSGI is what it should be:

aws:elasticbeanstalk:container:python:
  NumProcesses: '1'
  NumThreads: '15'
  StaticFiles: /static/=static/
  WSGIPath: path/to/wsgi.py

If any changes are made, make sure you save the file and confirm that everything is squared up by entering eb open in your terminal to open a browser window using the domain name specified in previous steps.

Tellurium answered 17/10, 2017 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.