title: PostgreSQL on AWS ECS: psycopg2.OperationalError invalid port number 5432
body: <p>I'm having a problem with database connection via psycopg2 on AWS ECS.
  I have an App container and a DB container. Containers are linked.</p>
  
  <p>The App has an entrypoint script that checks if the DB is up before starting an app server.</p>
  
  <pre><code>$ until psql -h "$DB_HOST" -U "$DB_USER" -c '' &amp;&amp; &gt;&amp;2 echo "Postgres is up"; do
      &gt;&amp;2 echo "Postgres is unavailable - sleeping"
      sleep 1
  done
  
  &gt; Is the server running on host "db" (172.17.0.3) and accepting
  &gt; TCP/IP connections on port 5432?
  &gt; Postgres is unavailable - sleeping
  &gt; Postgres is up
  </code></pre>
  
  <p>This part works fine, but as soon as the app server starts and tries to connect to the DB I get the following error:</p>
  
  <pre><code>psycopg2.OperationalError: invalid port number: "tcp://172.17.0.3:5432"
  </code></pre>
  
  <p>I have no idea what could be the case. This works fine when running locally with Docker.</p>
  
  <p>Any hints would be appreciated. Thanks!</p>