0
votes

I tried to deploy my Spring application on an AWS EC2 Ubuntu server, so far so good. My Mysql Database was created with RDS where I am possible to connect with e.g SequelPro and also with IntelliJ (When running the server locally but with external database)

When I want to run the Server on the EC2 Ubuntu System I run it with

java -jar

for test purposes only. (I know I have to install it as a service later)

But after a while I get this error when the server starts

> 018-06-20 16:26:37.122 ERROR 12116 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_171]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_171]
.
.
.
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_171]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_171]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_171]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_171]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2037) ~[mysql-connector-java-5.1.46.jar!/:5.1.46]
    ... 91 common frames omitted
Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[

Any ideas whats causing the problem? Ports are open in RDS and EC2...

RDS Security group defined as follows: Inbound:
enter image description here

Outbound: enter image description here

1
Seems security group attached to RDS not allowing traffic from your EC2 instance. Did you check it? - INVOKE Cloud
Edited a screenshot in the start post. The database is accessible from my local machine so why should it no be accessible from EC2? - Markus G.
There is a way you can limit communication to specific IP, which could just enable your local machine but not EC2. But, based on updated screenshots, your security group is configured wide open and should be accessible (by the way wide open ports are not a good practice in terms of security). - INVOKE Cloud
Yeah I know that this is not good for security, I just want I to run and afterwards I will configure everything security specific. Any other suggestions? - Markus G.
Do you have any special setup like private VPC (or) route tables etc.,? - INVOKE Cloud

1 Answers

0
votes

After several hours trying reinstalling etc. I forgot to change the connection string. I don't know why it still works locally with the wrong connection string but on ec2 it works now