Skip to content

Accessing RDS instance from EC2 instance in a different VPC [2024]

0

I have an RDS instance & an EC2 instance in 2 different VPCs. I want to access data in the RDS instance from my EC2 instance. I'm getting timeout errors when I try to connect to the database in the RDS instance.

Here's what I've done:

  1. VPC Peering between the 2 VPCs. DNS resolution is active for receiving and requesting VPCs.
  2. The route tables of both VPCs have been editted such that the destination = <other VPC's IPv4 CIDR range> & target = Peering Connection
  3. The Network ACLs are not an issue.
  4. Updated the security group of the RDS instance to allow inbound traffic from private IPv4 of the EC2 instance.
  5. Tried setting the RDS instance to 'Publically Accessible' & 'Not Publically Accessible' but still gives the same error.
  6. The RDS has public and private subnets. I've only updated the route table of the private subnet. I also tried updating the route table of public subnet, but no good.
  • Have you tried using the Reachability Analyzer?

  • Yes, the reachability analyzer says reachable with Availability zone crossed. However, when I try to ping or use telnet command from my ec2 instance (when I'm ssh'ed into int), the RDS instance is not reachable / gives timeout error when querying in the webapp.

  • Actually, I just reran the application after running the Reachability Analyzer & it's working.

1 Answer
2
Accepted Answer

If you make the RDS database publicly accessible, it wouldn't work because its DNS name would resolve to the public IP (and not the private IP routed via the VPC peering connection) from outside its local VPC. Without public access, it should work with the setup you're describing, if the RDS database is in a private subnet and if the outbound rules of the security group of the EC2 instance also permit traffic towards the RDS database.

Does the DNS name of the RDS database resolve to its correct private IP from the EC2 instance in the other VPC?

The VPC reachability analyser Rodney Lester suggested could very well find your problem. Your setup shouldn't involve anything more complex than what you described, so it could be as simple as a typo in IP routes or similar.

EXPERT
answered a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.