I’m trying to run eb create
to deploy my Django project to AWS. The error I’m getting is ERROR: ServiceError - Configuration validation exception: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/static/'): Unknown configuration setting.
I’m unsure what this error means and there’s not much I can find on it.
I’ve tried to define this variable in .ebextensions/django.config
.
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango.wsgi:application
aws:elasticbeanstalk:container:python:staticfiles:
/static/: 'frontend/views/build/static/'
My settings.py is configured with the following vars:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend/views/build/static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
I’m trying to run this ebs instance on Amazon Linux 2
2
Answers
If your environment uses a platform branch based on Amazon Linux 2, use the aws:elasticbeanstalk:environment:proxy:staticfiles namespace.
The following example configuration file tells the proxy server to serve files:
Example .ebextensions/django.config
Note:
STATIC_ROOT
path not inSTATICFILES_DIRS
Ah yes, Amazon Linux 2 documentation are not entirely up to speed.
Create a postdeploy hook file called .platform/hooks/01_collect_static.sh and make it executable with chmod.
Enter the following content:
On deploy, django will now collect your static files into the folder you’ve defined in settings.py.
Note, I include my migrate command here as well, such that my hook file looks like: