title: Django not connecting to PostGres on Elastic beanstalk
body: <p>I have setup django using Elastic Beanstalk on AWS EC2. However, trying to run the application gives me the following errors in the log file</p>
  
  <pre><code>File "/opt/python/run/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
    django.db.utils.OperationalError: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
  
     (ElasticBeanstalk::ExternalInvocationError)
  
  
  [2015-06-08T04:52:45.155Z] INFO  [5434]  - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_SportsGullyRest/Command 01_migrate] : Activity failed.
  [2015-06-08T04:52:45.155Z] INFO  [5434]  - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_SportsGullyRest] : Activity failed.
  [2015-06-08T04:52:45.155Z] INFO  [5434]  - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Activity failed.
  [2015-06-08T04:52:45.191Z] INFO  [5434]  - [CMD-AppDeploy/AppDeployStage0/EbExtensionPostBuild] : Activity failed.
  [2015-06-08T04:52:45.191Z] INFO  [5434]  - [CMD-AppDeploy/AppDeployStage0] : Activity failed.
  [2015-06-08T04:52:45.191Z] INFO  [5434]  - [CMD-AppDeploy] : Completed activity. Result:
    Command CMD-AppDeploy failed.
  [2015-06-08T04:58:30.553Z] INFO  [5642]  - [CMD-BundleLogs] : Starting activity...
  [2015-06-08T04:58:30.781Z] INFO  [5642]  - [CMD-BundleLogs/AddonsBefore] : Starting activity...
  [2015-06-08T04:58:30.781Z] INFO  [5642]  - [CMD-BundleLogs/AddonsBefore] : Completed activity.
  [2015-06-08T04:58:30.781Z] INFO  [5642]  - [CMD-BundleLogs/BundleLogs] : Starting activity...
  [2015-06-08T04:58:30.782Z] INFO  [5642]  - [CMD-BundleLogs/BundleLogs/BundleLogs] : Starting activity...
  </code></pre>
  
  <p>My Python Config file is:</p>
  
  <pre><code>option_settings:
    "aws:elasticbeanstalk:application:environment":
      DJANGO_SETTINGS_MODULE: "SportsGullyRest.settings"
      "PYTHONPATH": "/opt/python/current/app/SportsGullyRest:$PYTHONPATH"
      "ALLOWED_HOSTS": ".elasticbeanstalk.com"
    "aws:elasticbeanstalk:container:python":
      WSGIPath: SportsGullyRest/wsgi.py
      NumProcesses: 3
      NumThreads: 20
    "aws:elasticbeanstalk:container:python:staticfiles":
      "/static/": "/static/"
  </code></pre>
  
  <p>Is there something I'm missing to deploy the app?</p>
  
  <p>EDIT:</p>
  
  <p>This is my settings.py for DATABASES</p>
  
  <pre><code>if 'RDS_DB_NAME' in os.environ:
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.postgresql_psycopg2',
              'NAME': os.environ['RDS_DB_NAME'],
              'USER': os.environ['RDS_USERNAME'],
              'PASSWORD': os.environ['RDS_PASSWORD'],
              'HOST': os.environ['RDS_HOSTNAME'],
              'PORT': os.environ['RDS_PORT'],
          }
      }
  else:
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.postgresql_psycopg2',
              'NAME': 'dbname',
              'USER': 'sgadmin',
              'PASSWORD': 'root',
              'HOST': 'localhost',
              'PORT': '5432',
          }
      }
  </code></pre>