Django Collectstatic Command Fails In Aws Elastic Beanstalk Amazon Linux 2 Python 3 Platform
Solution 1:
Hey I just deployed my django app successfully with static files. Here's what my config looks like.
django.config
container_commands:01_collectstatic:command:"source $PYTHONPATH/activate && python manage.py collectstatic --noinput"option_settings:aws:elasticbeanstalk:container:python:WSGIPath:appname.wsgi:applicationaws:elasticbeanstalk:environment:proxy:staticfiles:/static:static
settings.py
# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/2.1/howto/static-files/STATIC_URL = '/static/'STATIC_ROOT = 'static'
The environment variables are for the ebs environment not the EC2 instance itself I think. I also don't see PYTHONPATH when I ssh into the EC2 instance but I do see it in the environment variables for my ebs environment in Environment > Configuration > Software on AWS Console
/var/app/venv/staging-LQM1lest/bin
This is my file structure:
┣ .ebextensions/
┃ ┗ django.config
┣ .elasticbeanstalk/
┃ ┗ config.yml
┣ appname/
Solution 2:
The trick here is that the full output of container_commands in /var/log/cfn-init-cmd.log
(Amazon Linux 2 Elastic Beanstalk released November 2020).
See related answer Running Django migrations when deploying to Elastic Beanstalk for full details.
PS. I highly recommend the whitenoise package rather than explicitly configuring aws:elasticbeanstalk:environment:proxy:staticfiles
. This simplifies your configuration because all files are served though Django and closely aligns the behaviour of your development and production environments.
Post a Comment for "Django Collectstatic Command Fails In Aws Elastic Beanstalk Amazon Linux 2 Python 3 Platform"