I'm running a Docker application on Amazon ECS Fargate and an RDS database in private subnets within my VPC. The application is unable to connect to or query the database. What should I check, and what is the recommended way to configure networking, security groups, routing, and database access between the Fargate tasks and RDS?
3 Answers
If the database and tasks are actually in separate VPCs, they won’t communicate just because both subnets are private. You’ll need VPC peering or a transit gateway, routes on both sides, compatible security-group and network-ACL rules, and working DNS resolution for the database endpoint. For a same-VPC setup, keep the database private and allow access only from the ECS task security group.
If both services are in the same VPC, different private subnets normally aren’t a problem. The first thing to check is the RDS security group: add an inbound rule for the database port, such as 5432 for PostgreSQL or 3306 for MySQL, with the ECS task security group as the source. Referencing the security group directly is better than allowing a broad subnet CIDR. Also verify that the task is using the correct RDS endpoint and that VPC DNS resolution is enabled.
Confirm the ECS tasks and RDS instance have routes through their respective subnet route tables, and check network ACLs if the security group configuration looks correct. The exact error helps narrow it down: a timeout often points to routing, NACLs, or blocked security groups, while a connection-refused error usually means the host is reachable but the service or port is not accepting connections. You can test DNS resolution and the database port from inside the running task.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures