Search code examples
djangoamazon-web-servicesamazon-elastic-beanstalk

ModuleNotFoundError: No module named 'application' when deploying Django app to AWS EB


I'm trying to deploy a Django Python 3.8 project to Elastic Beanstalk on Amazon Linux 2/3.4.2 64bit.

I have the following code in .ebeextensions/django.config:

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: pos.wsgi:application
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: pos.settings

I see this error all the time in the logs ModuleNotFoundError: No module named 'application'.

I've tried to write the config file this way, but still the same error:

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

Solution

  • Besides having this block in django.config I also had to specify the wsgi path in elastic beanstalk cinfiguration.

    option_settings:
      aws:elasticbeanstalk:application:environment:
        DJANGO_SETTINGS_MODULE: "pos.settings"
        PYTHONPATH: "/var/app/current:$PYTHONPATH"
      aws:elasticbeanstalk:container:python:
        WSGIPath: "pos.wsgi:application"
    

    enter image description here