ECS task timeouts connecting to RDS

My ECS container will connect to my RDS database initially and can even run a query. However very quickly after boot up, the connection will time out.

The error sometimes looks like a DNS one with the error message of:

  • OperationalError('[Errno -3] Temporary failure in name resolution')

Sometimes its a connection timeout:

  • OperationalError('connection timeout expired')

Notes and things I've tried:

  1. Security group has 5432 open, but I've tried having all ports open.
  2. Same VPC and different VPC
  3. My App Runner app can connect to the DB flawlessly (same code)
  4. My computer can connect to the database (same code)
  5. EC2 instances can connect to the database (same code)
  6. ECS container's role with RDS access, which doesn't make sense but I'm grasping at straws
  7. RDS is publicly accessible

I'm running Django 5.1 on Python 3.12.

I'm seriously out of solutions and am considering migrating off ECS to something else.

Back to Top