12

I'm attempting to deploy my first application to EB and am following along with this turorial: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

Unfortunately, I'm still getting a 502 error when deploying the final app. I'm confused because I've followed the directions to the tee.

I'm getting the following error

ImportError: Failed to find application, did you mean 'ebdjango/wsgi:application'?

I'm not sure what this means. Per the instructions, I edited the django.config file to include this text:

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

This appears to match my file structure:

- ebdjango
  -.ebextensions
    - django.config
  - .elasticbeanstalk
  - ebdjango
    _ __init__.py
    - settings.py
    - urls.py
    - wsgi.py
  - manage.py
  - requirements.txt

So the config file is set up correctly, right?

I'm running Python 3.7 and Django 2.2.

I know that EB searches for application.py, and I thought the config file is supposed to point the server towards my custom app? What am I missing here?

EDIT: I'm also getting this error:

ModuleNotFoundError: No module named 'ebdjango/wsgi'

Is something off about my file structure?

EDIT 2: I forgot to include the init.py file in my post, see Ben's comment.

Jon Hrovat
  • 585
  • 3
  • 19
  • Do you have an `__init__.py` file in the same directory as the `wsgi.py` file? – Ben May 27 '20 at 18:18
  • I do, it was created automatically when I executed startproject – Jon Hrovat May 27 '20 at 18:19
  • 3
    This error is because you're using Amazon Linux 2 as a platform, which use Gunicorn as WSGI Server but you've specified the "WSGIPath", which is not as per Gunicorn standard (you're still using syntax used for AL1 platforms). I see all of the 3 solution mentioned below are correct but none explained why to do those changes, so I thought to provide my 2 cents. You may find this [Medium Article] (https://medium.com/@justaboutcloud/how-to-deploy-a-django3-application-on-elastic-beanstalk-python3-7-and-amazon-linux-2-bd9b8447b55) handy, if you're looking for AL2 instructions. – dipak1296 Jun 08 '20 at 12:43

3 Answers3

8

I had the same issue. It is because of the Amazon Linux 2 machine image. Its configuration files are incompatible with those of the old version. Please see: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html. I ended up using the old version because the documentation says:

If you're using an Amazon Linux 2 platform version that is in beta for your evaluation, do not go to production. Wait until we release a supported platform version.

You can create an Elastic Beanstalk environment using the Amazon Linux machine image (old version) using the command line tool. Here are the commands (replace <...> with your data):

eb init -p python-3.6 <ApplicationName> --region <Region>
eb create <EnvironmentName> --elb-type application --platform "64bit Amazon Linux 2018.03 v2.9.10 running Python 3.6"

Update 2020-06-02 As I mentioned before, the issue is caused by Amazon Linux 2 platform because it uses Gunicorn, which has a WSGI syntax that is different than the previous version. The WSGIPath must be ebdjango.wsgi:application. Please see https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-container.html#python-namespaces.

Casper
  • 121
  • 5
4

In your django.config change:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: ebdjango.wsgi

And in your

import os
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "ebdjango.settings"
application = get_wsgi_application()
  • 2
    I also used this solution by using `ebdjango.wsgi` instead of `ebdjango/wsgi.py` but that was the only change I made. – ikonuk Jun 01 '20 at 19:22
1

I had the same problem today messing around with the django.config file. It finally worked for me when I changed the WSGI path in the configuration tab to ebdjango.wsgi:application.

kml
  • 11
  • 1