AWS RDS on Eclipse

639 views Asked by At

I know this question seems a repeat, but it's not and I have tried all the solutions I could find

PROBLEM:

I am running an AWS RDS instance for the database. It works fine when I connect to it using AWS EC2 instance(uses linux) but when I try it with my laptop, it doesn't work. I want to work on Eclipse( now I code on my laptop and test it on EC2 instance, its very annoying and very very inconvenient). Here is the error.

    com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.ConnectException
MESSAGE: Connection timed out: connect

STACKTRACE:

java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2771)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at execs.Connect.main(Connect.java:13)


** END NESTED EXCEPTION **



Last packet sent to the server was 1 ms ago.
Conn is null.
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2847)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at execs.Connect.main(Connect.java:13)

WHAT I HAVE TRIED:

  1. I have checked the security group for RDS its set to accept all inbound traffic for port 3306 (0.0.0.0/0) and all outbound traffic.
  2. I have enabled all the outbound and inbound traffic from eclipse on the Windows(laptop) firewall.
  3. Tried disabling the firewall entirely.
  4. Tried checking the eclipse's network configuration.

Nothing Happens!

1

There are 1 answers

0
300D7309EF17 On BEST ANSWER

Okay, per the comments on the question, I'm going to give an answer that works around the question. In other words, the straightforward answer is to do an insecure thing (open the database to public).

Here's the TLDR on the answer: create a tunnel to an ec2 instance, then tell Eclipse to open your side of the tunnel.

Here's the longer version, given assumptions that you have an ec2 instance with has access to the database (we'll call this instance ec2instance.amazonaws.com), you are on Windows, and you already know how ssh works. Finally, we'll call the database DNS abc.def.rds.amazonaws.com.

Prep

Refer to this stackoverflow answer. Ignore the plink.exe part, unless it works well for you.

In Putty, create a connection that forwards localhost:3306 to abc.def.rds.amazonaws.com:3306. In the "putty configuration" graphic at the linked answer, your source port is 3306, your destination is "abc.def.rds.amazonaws.com:3306".

On the main Session screen in putty, set the hostname to [email protected]. You can now hit save and save this session ("db tunnel", for instance).

Open the connection. You should have a blank terminal window. You can leave it alone, or you can use a generic command like watch -n15 date to keep the connection open.

Now, in Eclipse, set your connection string to localhost:3306. Use whatever username/password you've configured on the RDS mysql database.

The ssh tunnel will break if you lose your network connection. You've saved the putty configuration, so you can just log in again.