To avoid ElasticBeanstalk erasing your custom settings while autoscaling or re-initializing any instance in your environment you should use your .ebextensions
scripts to do any durable modification to your ec2 instance's config
files.
(After having tested these modifications as you did 'manually' using eb ssh
)
In that case you could use for example a sed command
to edit your wsgi.conf
file.
add the following container_command to one of you your yaml Elastic Beanstalk configuration file (ie: .ebextension/yourapp.config
):
03_wsgipass:
command: 'sed -i -f .ebextensions/wsgi_update.sed ../wsgi.conf'
It should then look like this :
container_commands:
01_migrate:
command: "django-admin.py migrate --noinput"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
03_wsgipass:
command: 'sed -i -f .ebextensions/wsgi_update.sed ../wsgi.conf'
create a new file in wsgi_update.sed
in the .ebextensions
folder with the following content:
/<Virtual/ a\
RewriteEngine On\
RewriteCond %{HTTP:Authorization} ^(.*)\
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
/<\/Virtual/ a\
WSGIPassAuthorization On
This is a small sed program for example that will add the apache mod_rewrite
rules inside your <VirtualHost>
block and the WSGIPassAuthorization
line after the closing tag </VirtualHost>
in your wsgi.conf
file
It will be executed on each application deployment to any existing or new instances created by autoscaling in your environment.
see Using the AWS Elastic Beanstalk Python Platform for more info