Kumaresh Babu N S
Kumaresh Babu N S

Reputation: 1698

Java web application cannot connect to AWS RDS DB Instance

I created DB Instance (MySQL) with Publicly Accessible option. In DB Security group, I opened MySQL Port for EC2 instance security group(Web server). In EC2 security group it allows ssh, web server ports. I can able to connect DB Instance from EC2 instance. I deployed web app on web server and it can't able to connect with RDS Instance.

I am getting the exception in my local web server:

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Server connection failure during transaction. Due to underlying exception: 'java.net.UnknownHostException: "kbawstry2.cdhtaamn5ynq.us-east-1.rds.amazonaws.com"'.

EC2 Security Group EC2 Security Group

DBInstance Security Group DBInstance Security Group

Using MySQL WorkBench, I can connect to RDS DB Instance using TCP/IP SSH Tunnelling option. But in Java Programming How can I connect with database?

Thanks in advance.

Upvotes: 1

Views: 4520

Answers (1)

Kumaresh Babu N S
Kumaresh Babu N S

Reputation: 1698

Finally I solved the issue. The problem is in application the way I mentioned connection string. I rectified and tested application in localhost then updated to tomcat server in EC2 instance. Another change in DB Security Group. I replaced source ip as EC2 instance's private IP address as both RDS and EC2 Instance are in same VPC.

Now It is working fine.

Upvotes: 1

Related Questions