Allow access to RDS instance from EC2 instance on same VPC

amazon-rdsamazon-web-services

I am having trouble gaining access to a MySQL RDS instance.

I am trying to connect to the RDS instance from an EC2 instance. Both the RDS instance and the EC2 instance are contained within the same VPC, myVPC. I have confirmed this by checking that VPC listed under the RDS instance and the RC2 instance matches.

Most of the questions about this issue that I found revolved around security groups. Many users had this difficulty and their problem was resolved by ensuring that the VPC security group associated with the RDS instance was the same as for their EC2 instance. In my case, both instances are on the same VPC and using the same security group. Within this security group, I have a rule that allows all inbound traffic across the full range of IPs of my VPC (ex, 172.35.0.0/16). In an attempt to get this working at all, I've allowed ALL traffic accross all ports from all IP addresses for this security group. This still has not worked.

Some reading of the documentation suggests that one should ensure that your subnets are associated with the same routing table used by your VPC. I've done this by going to the route table associated all subnets within myVPC with this routing table.

I have also tried it with and without an elastic IP. I am able to connect to my EC2 instance with the elastic IP address.

I realize that this question is asked quite a lot. As of yet, I haven't come accross one whose solution has solved my problem.

Edited: Adds more details of security settings
Both the ec2 instance and RDS use the same security group.
Within that security group is a line that says something like

MYSQL TCP 3306 172.35.0.0/16 My CIDR range

I added

MYSQL TCP 3306 172.35.0.1/32 My ec2 instance private IP

None of the above worked.

What DID work was under my network ACL settings I changed a line from

1 MySQL(3306) TCP(6) 3306 172.35.0.1/32 ALLOW

to

1 ALL TRAFFIC ALL ALL 0.0.0.0/32 ALLOW

So my problem has been worked out, but now I have another question. How can I avoid having 3306 open to all inbound connections. I may post this as a new question and link here.

Best Answer

I had this issue myself a couple of weeks ago. In my case, I had forgotten to allow outbound traffic on port 3306 for my EC2 instance to the VPC CIDR. Try adding an outbound rule to your EC2 instance security group looking something like this:

Type    Protocol    Port Range    Destination
MYSQL   TCP         3306          172.35.0.0/16