title: How to modify apache VirtualHost in AWS ElasticBeanstalk
body: <p>I want to insert some lines in apache  directive of my instances in ElasticBeanstalk. (My instances are 64bit Amazon Linux 2016.03 v2.1.0 running Python 2.7 for running Django with mod_wsgi).</p>
  
  <p>I have created a file "configuration_httpd.py" :</p>
  
  <pre><code># -*- coding: utf-8 -*-
  import os
  import fileinput
  
  current_dir = os.path.dirname(os.path.abspath(__file__))
  
  custom_conf = open(current_dir+'/httpd.conf','r').read()
  
  try:
      for line in fileinput.input('/etc/httpd/conf.d/wsgi.conf', inplace=1):
          if line.startswith('&lt;/VirtualHost&gt;'):
              print custom_conf
              print line,
          else:
              print line,
  except OSError:
      print "Error '/etc/httpd/conf.d/wsgi.conf' unknown"
  </code></pre>
  
  <p>It's executed on deployments with .ebextensions/django.config file :</p>
  
  <pre><code>packages:
    yum:
      libjpeg-turbo-devel: []
      libpng-devel: []
  
  container_commands:
    01_setup_apache:
      command: "python configure_httpd.py"
    02_migrate:
      command: "python manage.py migrate"
      leader_only: true
    03_collectstatic:
      command: "python manage.py collectstatic --noinput"
  
  option_settings:
    aws:elasticbeanstalk:application:environment:
      DJANGO_SETTINGS_MODULE: "djangoproject.settings"
      PYTHONPATH: "/opt/python/current/app/djangoproject:$PYTHONPATH"
    aws:elasticbeanstalk:container:python:
      WSGIPath: "djangoproject/wsgi.py"
  </code></pre>
  
  <p>This file is executed but the file '/etc/httpd/conf.d/wsgi.conf' is intact.</p>
  
  <p>Why ?</p>
  
  <p>When I log into my instance with ssh I can run the script "configure_httpd.py" with sudo and it works.</p>
  
  <p>Why this script doesn't work at deployment ?</p>
  
  <p>Any help please. Thank you</p>