0

I'm using SQLAlchemy inside a Lambda with RDS Proxy (PostgreSQL).

This configuration works, but when I'm invoking about 100 lambdas at the same time some lambdas receive a timeout (3 seconds) even when I'm increasing the timeout for 30 seconds I still get a timeout.

After investigating where this timeout comes from, I concluded that the SQLAlchemy hangs when it tries to get a connection to the database.

I thought the RDS proxy could easily handle 100+ concurrent connections.

Here is my engine configuration:

    db_url = f"postgresql://{db_username}:{secret}@{db_hostname}:{db_port}/{db_name}"
    engine = create_engine(
        db_url, 
        echo=True, 
        echo_pool="debug", 
        poolclass=NullPool)

Usually, when SQLAlchemy creates a connection it logs the following:

DEBUG sqlalchemy.pool.impl.NullPool Created new connection <connection object at 0x7f074ebe5580; dsn: 'user=user password=xxx dbname=dbname host=rds-default.{rds-proxy-id}.{region}.rds.amazonaws.com port=port', closed: 0>

But sometimes it will just hang and won't log anything and eventually timeout.

Any help would be appreciated

T.sagiv
  • 325
  • 2
  • 9

0 Answers0