Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot app running on AWS-EC2 unable to connect to MySQL AWS-RDS database

I am having problems running an app I have developed in an EC2 instance. When I execute the .jar (java -jar app.jar), the SpringBoot app starts but it fails when trying to connect to my MySQL RDS database. The thing is when I run the app locally on my machine, It has no issues with the DB connection.

I have opened the port where the app is running (8090) and MySql port as well (3306) for inbound and outbound traffic:

enter image description here

This is the error I get:

2016-09-23 17:46:38.132  INFO 10161 --- [main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8090
2016-09-23 17:46:38.604  INFO 10161 --- [main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-09-23 17:46:38.605  INFO 10161 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.54
2016-09-23 17:46:38.724  INFO 10161 --- [ost startStop 1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-09-23 17:46:38.725  INFO 10161 --- [ost startStop 1] o.s.web.context.ContextLoader: Root WebApplicationContext: initialization completed in 5028 ms
2016-09-23 17:48:48.476 ERROR 10161 --- [ost startStop 1] o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool.

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.

Any ideas how can i solve this problem?

Thank you very much for your help

Regards

Andres

like image 375
A Torre Avatar asked Mar 11 '23 01:03

A Torre


1 Answers

From your description and log file, it's likely that network configuration is the cause here.

You might want to draw the network topology of your instances (region/availability zone, VPC, subnet, network acl, security group). This will be very helpful when you do more complex development work. There are good references: VPC Introduction and Security in your VPC and Scenarios for Accessing a DB Instance in a VPC

I suggest the following actions for your troubleshooting:

  • Check security group (SG) configuration of your EC2 instance and RDS instance.
    You can check this by going to EC2 Dashboard/RDS Dashboard -> Click on an instance and look at "Security Group" description, or you can click on the Setting icon (Show/Hide columns) and tick "Security Groups".

    In RDS's SG configuration: make sure you have enable access from EC2 instance's SG to port 3306. You can do this by putting EC2 instance's SG ID into Source field of the config, as a "Custom IP" value. See the 1st scenario in the above reference for more detail.

  • Use mysql command line to test the connection between EC2 instance and RDS.

Hope it helps.

like image 98
Liem Pham Avatar answered Mar 14 '23 00:03

Liem Pham