I am currently trying to connect to an amazon RDS from a lambda function. The problem I am facing is that I do not get an error but neither I manage to get a connection, so I am not sure how to proceed. I do not have a timeout, or an error with the parameters, but the object "con" is always null.
To do this I am doing the following:
Connection con = null;
String jdbcUrl2 = "jdbc:mysql://" + "connectionValueExample-zone.rds.amazonaws.com" + ":" + "3306" + "/" + "botdb" + "?user=" + "bot" + "&password=" + "PWvalueExample";
con = DriverManager.getConnection(jdbcUrl2);
After every step I check with prints() how it's going. After I try to stablish the connection I try to catch it, because while I am not getting exceptions right now, the object con never stops being null, so I do not stablish a connection.
catch (SQLException e) {
e.toString();
log.warn(e.toString());
} catch (Exception e) {
System.out.println("excepcion no capturada ");
e.toString();
}
The second catch is just in case I was missing something, originally it was not there.
All in all, the code looks something like:
@Override
public String handleRequest(Object input, Context context) {
context.getLogger().log("Input: " + input);
Connection con = null;
try {
String jdbcUrl2 = "jdbc:mysql://" + "value-zone.rds.amazonaws.com" + ":" + "3306" + "/" + "botdb" + "?user=" + "bot" + "&password=" + "PW";
con = DriverManager.getConnection(jdbcUrl2);
} catch (SQLException e) {
e.toString();
log.warn(e.toString());
} catch (Exception e) {
System.out.println("excepcion no capturada ");
e.toString();
}
String status = null;
if (con != null) {
status = "conexion establecida";
System.out.println("connection stablished");
} else status = "connection failed";
return status;
}
Edit:
I am now capturing slightly better the exceptions and get the following message:
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.
At this point I am unsure if the Strin jdbcURL is not properly formed OR why is the connection failing.