Reputation: 3939
So I have a primary RDS in us-east-1
& a replica in us-west-1
. Both are inside VPCs in their respective regions. I want to have one of my EC2 instances in us-east-1
connect to the replica instance.
A simple solution is to enable public access for the RDS replica and add the IP of the EC2 to its security group and it works.
But instead of allowing a static IP, I would like to allow access to the entire CIDR range of my us-east-1
VPC and also I don't want my instances to be public accessible.
To do this, I've setup a VPC peering connection between the two regions and I have added entries in the routing tables of both the VPCs to forward traffic to each other's CIDR ranges to the peering connections.
The CIRD range of the EC2 instance is 172.31.0.0/16
and I have added this to the security group of the RDS replica in the us-west-1
region. But for some reason the RDS is not reachable from my EC2.
Have I missed anything else? Thanks!
To summarize my setup:
US EAST:
172.31.0.0/16
10.0.0.0/16
routes to the peering connection of us-west-1
VPC.172.31.5.234
US WEST:
VPC CIDR: 10.0.0.0/16
Route Table entry: Destination 172.31.0.0/16
routes to the peering connection of us-east-1
VPC.
RDS:
172.31.0.0/16
Upvotes: 4
Views: 5247
Reputation: 269161
To reproduce your situation, I did the following:
In us-east-1
:
us-east-1
with a CIDR of 172.31.0.0/16
using the "VPC with Public and Private Subnets" VPC WizardIn us-west-1
:
us-west-1
with a CIDR of 10.0.0.0/16
using the "VPC with Public and Private Subnets" VPC WizardPublicly accessible = No
Setup peering:
us-east-1
, created a Peering Connection Request to the VPC in us-west-1
us-west-1
, accepted the Peering RequestConfigure routing:
us-east-1
, configured the Public Route Table (used by the EC2 instance) to route 10.0.0.0/16
traffic to the peered VPCus-west-1
, configured the Private Route Table (used by the RDS instance) to route 172.31.0.0/16
traffic to the peered VPCSecurity Groups:
us-east-1
, created a security group (App-SG
) that allows inbound port 22 connections from 0.0.0.0/0
. Associated it to the EC2 instance.us-west-1
, created a security group (RDS-SG
) that allows inbound port 3306 connections from 10.0.0.0/16
(which is the other side of the peering connection). Associated it to the RDS instance.Test:
us-east-1
sudo yum install mysql
)mysql -u master -p -h xxx.yyy.us-west-1.rds.amazonaws.com
This successfully connected to the RDS database across the peering connection.
FYI, the DNS name of the database resolved to 10.0.2.40
(which is in the CIDR range of the us-west-1 VPC). This DNS resolution worked from both VPCs.
In summary, the important bits are:
Upvotes: 11