Search code examples
amazon-web-servicesamazon-ec2amazon-rdsaws-security-group

When trying to run Ec2 with RDS, connection times out. Do my security group rules look right?


I have set up an Ec2 with files from S3 and a MySQL RDS. If I run my Node app locally, I can connect to the RDS and it works just fine. But when I SSH into the Ec2 and npm start, it never connects and the connection times out. Only error is Error Connection Timed Out.

I have a screenshot below of the RDS's security group inbound rules. Notice I have a single IP for my desktop (which is how I was able to connect by running the app locally).

This is the first time I've set up an Ec2 and RDS. Does anything look off? I know I don't need all of those rules, but what am I missing? How can I troubleshoot? Also attached screen shot of EC2's outbound SG rules.

Also, I configured a MySQL server on the Ec2 and can SSH into the Ec2 and connect to the RDS database just fine from that. Is there another simple way I can test if the Ec2 is connecting to RDS?

enter image description here

enter image description here


Solution

  • I believe the initial problem was not actually with the EC2 to RDS connection, although the suggestions above are essential. The home page of the app does not require any data from the database but it was not loading at all, so I finally figured out it was a connection problem between my computer and the EC2 using the public IP address. This should have been something to check earlier - the clues being the home page conundrum and the successful MySQL connection on SSH.

    I simply needed to add an inbound rule on the EC2's security group for port 3000. It had been set to All Traffic. Any idea why All Traffic would not work?