Week 5 - psycopg_pool.PoolTimeout: couldn't get a connection after 30.0 sec

This connection error is one of those errors that trip up many campers. Basically, the error message is telling you that your computer is unable to connect to the database. In my case, it was the AWS-side RDS Postgresql DB.

Error

Traceback (most recent call last):
  File "/workspace/aws-bootcamp-cruddur-2023/./backend-flask/bin/ddb/seed", line 112, in <module>
    users = get_user_uuids()
            ^^^^^^^^^^^^^^^^
  File "/workspace/aws-bootcamp-cruddur-2023/./backend-flask/bin/ddb/seed", line 77, in get_user_uuids
    users = db.query_json_array(sql, {
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/aws-bootcamp-cruddur-2023/backend-flask/lib/db.py", line 133, in query_json_array
    with self.pool.connection() as conn:
  File "/home/gitpod/.pyenv/versions/3.11.1/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/psycopg_pool/pool.py", line 138, in connection
    conn = self.getconn(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/psycopg_pool/pool.py", line 182, in getconn
    conn = pos.wait(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/psycopg_pool/pool.py", line 745, in wait
    raise self.error
psycopg_pool.PoolTimeout: couldn't get a connection after 30.0 sec

Solution

  • ✅ Check if the AWS-side security group rule is updated with your current GITPOD_IP (or your machine's IP in case you develep locally).

    • Example:

        == db-connect
        psql: error: connection to server at 
        "<AWS_RDS_DB_identifier>.us-east-1.rds.amazonaws.com" 
        (52.44.13.66), port 5432 failed: 
        Connection timed out
                Is the server running on that host and 
                accepting TCP/IP connections?
      

✅ Is the database NOT running…? → Run your database (postgres or DynamoDB)

✅ User’s cognito_user_id does not match? → Update cognito_user_id

✅ Are there data in the database? → Seed some conversation data.

0
Subscribe to my newsletter

Read articles from Mariachi in a Jar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mariachi in a Jar
Mariachi in a Jar

Previously cross-cultural communicator, now a machine-human communicator. Currently working as a software QA. Building solid cloud skill sets to transition into the Cloud world.