-1

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!

  • what's your setting for "Publicly Accessible" on the database? Is this in a (default) VPC? – tedder42 Jun 18 '15 at 23:50
  • Thank you so much @tedder42. Its no, but how do I change it – crackerjack Jun 19 '15 at 00:11
  • I completely agree with you and that is what the setup is right now. I know its a terrible idea but I'm learning and practicing and I want the setup to be convenient so I could use it from eclipse. I think I'd have to create another instance using the previous's snapshot. – crackerjack Jun 19 '15 at 00:30
  • you can use it from Eclipse with an ssh tunnel. You simply tell Eclipse the database is at localhost:3306 and start the tunnel. – tedder42 Jun 19 '15 at 00:31
  • @tedder42 could you please elaborate on that. I'm new to this. It still doesnt work I created another instance with public accessibility as yes and I get same error. – crackerjack Jun 19 '15 at 00:54
  • it's too much work for a comment. If you'll accept it as an answer, I'll try to give step-by-step directions as an answer. – tedder42 Jun 19 '15 at 00:55
  • @tedder42 ya sure. Thanks man Cheers !. I'd even give an up if I could – crackerjack Jun 19 '15 at 00:56

1 Answers1

0

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 yourusername@ec2instance.amazonaws.com. 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.

Community
  • 1
  • 1
tedder42
  • 23,519
  • 13
  • 86
  • 102