1

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.

12
  • can you also tell the outbound rule for your ec2 instance security group? Commented Jan 8, 2017 at 12:30
  • All traffic are opened in outbound both in EC2 Security group and DB Instance Security Group. Commented Jan 8, 2017 at 12:41
  • 1
    What DNS server is configured for the EC2 instance? Commented Jan 8, 2017 at 12:56
  • Really, I don't know. I installed and configure apache-tomcat 7 for deploying web apps. Commented Jan 8, 2017 at 13:09
  • @KumareshBabu Could you share the code, where DB connection code is written ? Commented Jan 8, 2017 at 15:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

it would be better if you mention what did you change in the connection string as well.
In code, I was mentioned double quotes for connection string so it was getting failed to connect with RDS database. Next I rectified the problem made it works.
I faced same error but in my case i haven't configured rule as well. I removed double quotes from property file, Its started working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.