title: How to add Basic Auth to Python REST API hosted on Amazon Elastic Beanstalk?
body: <p>I develop a HTTP REST API using Python flask, which is hosted on Amazon Elastic Beanstalk (platform: Python 3.4). To secure the API I want to add Basic Authentication to it. </p>
  
  <p>First approach is to add the Basic Auth directly in the Python application (as described <a href="http://flask.pocoo.org/snippets/8/" rel="nofollow">here</a>). This requires to enable auth forwarding by adding a .conf file in the .ebextensions directory:</p>
  
  <pre><code>container_commands:
    01_wsgipass:
      command: 'echo "WSGIPassAuthorization On" &gt;&gt; ../wsgi.conf'
  </code></pre>
  
  <p>Second approach is to configure the Elastic Beanstalk container by adding a .config file in the .ebextensions directory. The following configuration I have from <a href="http://enrico.quora.com/How-to-protect-an-elastic-beanstalk-environment" rel="nofollow">here</a>. However this is not working for me.</p>
  
  <pre><code>files:
    "/etc/httpd/conf.d/allow_override.conf":
      mode: "000644"
      owner: ec2-user
      group: ec2-user
      encoding: plain
      content: |
        &lt;Directory /opt/python/current/app/&gt;
          AllowOverride AuthConfig
        &lt;/Directory&gt;
  
    "/etc/httpd/conf.d/auth.conf":
      mode: "000644"
      owner: ec2-user
      group: ec2-user
      encoding: plain
      content: |
        &lt;Directory /opt/python/current/app/&gt;
          AuthType Basic
          AuthName "My Application"
          AuthUserFile /etc/httpd/.htpasswd
          Require valid-user
        &lt;/Directory&gt;
  
    "/etc/httpd/.htpasswd":
      mode: "000644"
      owner: ec2-user
      group: ec2-user
      encoding: plain
      content: |
        appuser:pw1234
  </code></pre>
  
  <p>What is the best approach to add Basic Auth to the Python API (under the condition that SSL may be added later on too) If the second one, why is the .conf file not working.</p>