I have a MySQL RDS instance in AWS which has been set up properly.
I also have a Linux EC2 instance in AWS.
However, I can't connect to my RDS instance from the EC2 instance.
I can connect to the RDS instance from my own laptop, however.
I suspect it is one of four things
- interface binding of the RDS instance - it is listening on the external interface but not on the internal one
- firewall for the RDS instance - it is allowed connections from outside the AWS network but not from inside
- firewall for the EC2 instance - it is not allowing connections to the RDS instance
- name resolution on the EC2 instance - for some reason the name of the RDS instance is not resolving to the right IP address
However, I have checked all of these to the best of my knowledge, and they seem to be in order.
What should I be looking at?
Update 1: Following a question by @mbaird, I have checked that both the EC2 instance and the RDS instance are on the same VPC. What implications does that have?
Update 2: Following a question by the user @"Michael - sqlbot", when I say cannot connect, when running mysql at the command line, with
mysql --host=<my-hostname> --port=3306 --user=<user> --password=<password>
I can connect form my own laptop, but when I try connecting from my EC2 instance, it just sits there doing nothing. After a while, I get the message
ERROR 2003 (HY000): Can't connect to MySQL server on '<my-hostname>' (110)
Also, when trying to connect to it from my Java application server, I get the following in my stack trace
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
...
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
...
Caused by: java.net.ConnectException: Connection timed out
Update 3: The DNS resolution is different depending on whether I am internal to AWS or external.
nslookup <my-hostname>
on my laptop results in an IP address 52.11.*.*
range, while doing the same from my EC2 instance results in an IP address in the 172.31.*.*
range.