Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Customize AWS Elastic Beanstalk wsgi.conf without being wiped out after update of environment variables
files:
"/opt/elasticbeanstalk/hooks/configdeploy/pre/99patchwsgi.py": &file
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import config
def main():
if 'EB_SYSTEM_STARTUP' in os.environ:
return
try:
WSGI_STAGING_CONFIG = config.get_container_config('wsgi_staging_config')
config.execute(['mkdir', '-p', '/etc/httpd/wsgi.conf.d'])
config.execute(['sed', '-i', '/\<VirtualHost \*:80\>/a IncludeOptional /etc/httpd/wsgi.conf.d/*.conf', WSGI_STAGING_CONFIG])
except Exception, e:
config.emit_error_event(config.USER_ERROR_MESSAGES['badappconfig'])
config.diagnostic('Error patching wsgi.conf during configdeploy/pre: %s' % str(e))
sys.exit(1)
if __name__ == '__main__':
config.configure_stdout_logger()
main()
"/opt/elasticbeanstalk/hooks/appdeploy/pre/99patchwsgi.py": *file
"/etc/httpd/wsgi.conf.d/enable_auth_header.conf":
mode: "000755"
owner: root
group: root
content: |
WSGIPassAuthorization On
@djshen-ponddy

This comment has been minimized.

Copy link
Owner Author

@djshen-ponddy djshen-ponddy commented Oct 13, 2017

This script will create two hook files:
/opt/elasticbeanstalk/hooks/configdeploy/pre/99patchwsgi.py
/opt/elasticbeanstalk/hooks/appdeploy/pre/99patchwsgi.py
and will be executed during app deploy or config update.

We can put customized apache configs that must be inside VirtualHost, for example, enable_auth_header.conf,
in /etc/httpd/wsgi.conf.d directory, and the config files will be included by IncludeOptional /etc/httpd/wsgi.conf.d*.conf.

@michealjroberts

This comment has been minimized.

Copy link

@michealjroberts michealjroberts commented Oct 23, 2019

Is there a way to use this to force http => https redirects?

@ankitbeohar90

This comment has been minimized.

Copy link

@ankitbeohar90 ankitbeohar90 commented Dec 17, 2019

@djshen-ponddy can you elaborate steps how to deploy this script and will it be applicable in autoscale case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment