pythondjangoamazon-web-servicesamazon-elastic-beanstalkstatic-files

AWS Elastic Beanstalk can not find static files for Django App


I am having a little trouble setting up the static folders on elastic beanstalk for a django app I created. I manged to get the app to run without any of the css/js/etc. My file structure is:

|.ebextensions
|    --django.config
|.elasticbeanstalk
|    --config.yml
|django_app
|    --core
|    --blog
|    --other apps..
|config
|    --settings
|        --base.py
|        --local.py
|        --production.py
|    --asgi.py
|    --urls.py
|    --wsgi.py
|static
|    --blog
|        --css/js/etc
|    --other apps
|manage.py
|requirements.txt
|secrets.json

in my django.config I have it set up like so:

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: config.settings.production
  aws:elasticbeanstalk:container:python:
    WSGIPath: config.wsgi:application
    NumProcesses: 3
    NumThreads: 20

and for my static settings in base.py (production/local.py do import base.py):

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = "static"

I had a similar problem with flask but it didn't give me this much trouble. I have tried to follow some of the solutions that are on here but nothing has worked just yet or I am misinterpreting something. Any help is appreciated!


Solution

  • You have to add an additional option in your django.config option_settings, and it depends of the Elastic Beanstalk platform that you use.

    I think that you are using the new platform platform/Python 3.7 running on 64bit Amazon Linux 2. If yes, use:

    aws:elasticbeanstalk:environment:proxy:staticfiles:
        /static: static
    

    But if you are using platform/Python 3.6 running on 64bit Amazon Linux or older, use:

    aws:elasticbeanstalk:container:python:staticfiles:
        /static: static
    

    You can check this link for more details.

    If you don't know the platform you use, there are different ways to know it: