Search code examples
amazon-web-servicesaws-lambdaamazon-rdspostgresql-15

Connection issue from Lambda to RDS PostgreSQL 15


In RDS PotgreSQL 12, I can connect to DB using psycopg2 from local and also from Lambda function.
But when I upgrade to RDS PotgreSQL 15, I cannot connect to DB from Lambda anymore (I still can connect from local though).
The error that Lambda gives is:

FATAL:  no pg_hba.conf entry for host ***, user ***, database ***, no encryption

This is how I connect:

import psycopg2
connection_psql = psycopg2.connect(user=***
                                    , password=***
                                    , port="5432"
                                    , database=***
                                    , host=***)

Solution

  • The issue was that in Lambda I was using a version of psycopg2 without ssl (from this repo). Apparently in recent versions of Postgres, ssl is required. The same repo has versions with ssl as well. Using those resolved the issue.