Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk: WSGI path incorrect?

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.

like image 523
Jon Hrovat Avatar asked May 27 '20 17:05

Jon Hrovat


2 Answers

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.

like image 133
Casper Avatar answered Sep 19 '22 01:09

Casper


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()
like image 41
David Pulloquinga Avatar answered Sep 17 '22 01:09

David Pulloquinga