Why can't I connect AWS RDS instance from EC2 instance in another VPC after peering
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Connecting an AWS RDS instance from an EC2 instance in another VPC after establishing a peering connection can occasionally result in connectivity issues. This situation generally arises due to several technical reasons. Here we dive into various aspects, where we will discuss networking concepts, configurations, and measures necessary to establish a successful connection.
VPC Peering Overview
VPC Peering allows you to connect one VPC with another via AWS's network infrastructure. However, just establishing peering doesn't automatically mean all resources can talk to each other. Here’s why:
- Routing Configuration
- Security Groups
- Network ACLs
- RDS Configuration
Key Considerations and Common Issues
Routing Configuration
Once the VPC Peering connection is established, it's crucial to appropriately configure the route tables in both VPCs to direct traffic through the peering connection.
- Route Tables: Ensure that the routing table associated with the EC2 instance’s subnet has the route to the RDS instance’s CIDR block pointing to the peering connection and vice versa.
Security Groups
Security groups act as virtual firewalls that control inbound and outbound traffic. Misconfigured security groups often block the communication.
- RDS Security Group: The security group should allow inbound access from the IP range of the EC2 instance's VPC.
- EC2 Security Group: While less common, ensure rules here don't block outbound requests to the RDS instance.
Network ACLs
Network Access Control Lists (NACLs) may also interfere if they deny traffic between your peered VPCs.
- Check NACL Rules: Both inbound and outbound rules should permit traffic to and from the respective subnets in the peered VPC.
RDS Configuration
Occasionally, the RDS itself might be configured in ways that restrict its accessibility.
- Public Access: Ensure the RDS instance allows private connectivity by appropriately setting up a private subnet. Avoid enabling public access in this scenario.
- Endpoint: Using the correct endpoint, either a private IP or DNS, is essential for accessing the RDS instance.
Troubleshooting Steps
- Verify Peering Connection Status:
- Confirm the state is "active."
- Route Table Verifications:
- Double-check entries for each VPC that point to the VPC peering.
- Security Group Rules:
- Both inbound and outbound rules for the EC2 and RDS security groups should properly allow access.
- Check DNS Resolution:
- Make sure DNS resolution is enabled for the VPC and try using the private IP address of RDS for connection testing.
- Use VPC Flow Logs:
- Examine VPC Flow Logs to understand whether traffic is being blocked subconsciously and where.
Example Configuration
Here’s a possible setup after VPC peering to access an RDS instance.
Route Table Entry
| Source | Destination CIDR | Target | Notes |
| VPC-A | 10.1.0.0/16 | pcx-xxxxxx | For traffic from VPC-B to access VPC-A |
| VPC-B | 10.2.0.0/16 | pcx-xxxxxx | For traffic from VPC-A to access VPC-B |
Security Group Entry
- RDS Security Group: Allow inbound from the CIDR of VPC-B, for example, TCP Port 5432 for PostgreSQL.
| Source | Protocol | Port range | Destination |
| 10.2.0.0/16 | TCP | 5432 | RDS Instance |
- EC2 Security Group: Ensure outbound requests to TCP Port 5432 is not denied.
Additional Considerations
- Subnet Configuration: Make sure the subnets are adequately configured to communicate over internal IP ranges.
- IAM Roles and Policies: Ensure that IAM policies do not blockade specific networking actions over the EC2 and RDS, though this is rare.
- Latency and Bandwidth: Acknowledge that cross-VPC communication might introduce additional latency and potential bandwidth limitations.
By addressing these areas, the connectivity issue between an EC2 instance and an RDS instance post-VPC peering can be effectively resolved. Always remember that the robustness of cloud networking hinges on the precise configuration of policies, routing paths, and security measures.

