18

I am using this tutorial: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

I create the .ebextensions directory inside the root directory, and put this django.config file in it:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: mysite/wsgi.py

I've also tried setting the path to mysite/mysite/wsgi.py because I saw that work somewhere but it did not help me.

Everywhere I look shows a different .config file with different arrangements, and I don't know where to go from here. How can I properly set my WSGIPath in Elastic Beanstalk?

conjenks
  • 409
  • 1
  • 6
  • 18

6 Answers6

25

[Solution]

1 eb config

2 Change the WSGIPath there from application.py to mysite/wsgi.py

That's It

karan
  • 398
  • 4
  • 5
  • 1
    Does the django.config not do anything then? – Aviendha Apr 03 '18 at 14:49
  • 3
    Three years later and this is still helping people. The really needs clearing up in the AWS tutorial! – goose Jun 30 '19 at 11:28
  • 1
    Does the eb config in the answer refer to the django.config file? – Chris Claude Dec 02 '19 at 14:31
  • this comment was very helpful! -- one note, it is specific to using python 3.6 (which is now deprecated, and unfortunately still used in the tutorial linked). this issue shouldn't happen when using python 3.8 and Linux 2 ([platform history](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platform-history-python.html)) – willwrighteng Sep 25 '21 at 19:12
2

I ran into a similar issue, and it seemed to resolve when I put .elasticbeanstalk in the same directory as .ebextensions, rather than having it be a child directory. Then I had to run eb config to fix the wsgi file that it was de facto picking up, and now I have a running app.

Aviendha
  • 763
  • 6
  • 16
2

Make sure that .ebextensions isn't ignored. EB looks for .ignore file (.ebignore by default and if it doesnt exists but .gitignore does, it will use it) and deploy only the files that are not ignored. Had a similar issue with my local_settings.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore

Michał D
  • 21
  • 1
1

If you see the following error:

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

Note the following:

  1. EC2 (server) instances in EB (platform) run Apache.
  2. Apache finds Python apps according to our WSGIPATH.
  3. 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.

Display name
  • 753
  • 10
  • 28
1

I did not use console but GUI.

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

where could be problem : Creating .zip file

select all : files of your project (not the project folder)

Note : weworkout is my django project (created by django-admin startproject weworkout)

Right way : select all files

Right way

Wrong way : selecting project folder

wrong way


Also this is the only change you have to do to your django project before uploading

weworkout/.ebextensions/django.config file contains

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: weworkout/wsgi.py

Note : .ebextensions is in same folder as manage.py

Vishal Singh
  • 725
  • 7
  • 16
0

Check if your Django.config file was saved with the correct extension. I had the same issue and the problem was that the file was being saved as a TXT file instead of config file.

Ale Silva
  • 73
  • 1
  • 1
  • 5