I am attempting to query a MySQL database from a java program on EC2. My database is stored on Amazon Web Services (AWS) RDS.
When I test my java program from my local tomcat server, I successfully query the RDS database. However, when I query my RDS database from my EC2 instance, I fail to connect.
In my attempts to solve this problem, I investigated my security settings. I've set up an RDS security group associated with my EC2 Security group that is associated with my instance. In my EC2 security group I've enabled all types of inbound traffic to all ports.
Other answers to similar questions suggest that setting up the RDS security groups to accept connections from the EC2 instance is the resolution to this problem. However, I have seemingly done this, yet cannot connect from my EC2 instance (but can from my local machine).
Am I overlooking something?
My guess would be, your EC2 instance is probably in different VPC , and you have made the RDS db instance private or you did not launch it in the specific vpc where your EC2 instance is located in.
Related
I have hosted a play framework web application on Amazon EC2 instance. The application is not able to connect to a mysql database located on the Amazon RDS instance. When I run the play framework web application on my local computer it successfully connects to the database on the Amazon RDS instance. I checked the database connection credentials in the production conf file many times. Looks correct.
When I do
mysql -h********.rds.amazonaws.com -p****** -u****** db_name
from the local computer it quickly connects. But when I try same connection to RDS from EC2 it throws:
ERROR 2003 (HY000): Can't connect to MySQL server on ********.rds.amazonaws.com
Can anyone kindly help me with this or suggest anything that I may be possibly missing.
Is RDS in VPC?
Yes, Check if EC2 is also in VPC or not.
No, Check security group that EC2 is in, allows the communication over database port
For more info and scenarios, head here
I have 2 projects.
Spring Restful Webservice
AngularJS
Database is MySQL.
i am new to AWS, I want to host my application using AWS. So i want to deploy these projects on AWS.
When i create MySQL database on AWS, then what will be the DB_URL then i can use it on my java application.
When i deploy the WAR file on AWS, then what will be the URL then i can use it on my AngularJS application
Database: use RDS Mysql. After create, go detail of RDS instance you will get RDS Endpoint with this pattern: RDS_INSTANCE_NAME.XXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com and default port 3306. You can access this RDS with that endpoint and user/pass as the local database (Import/export, Create schema,...)
About the web layer, you can create 2 EC2 instances: 1 for Web-service, 1 for AngrulaJS or create 1 EC2 instance and deploy both of them into that EC2 instance.
You need SSH key to access via ssh. Then install your web container into EC2 instances and deploy as local server
AngrulaJS web: There are many ways to public your app:
you can use Route53 to create A Record point to public IP of EC2 instance (Containt AngrularJS app)
Use Internet-facing ELB point to EC2 instance.
Use public IP that associated to EC2 instance.
I found a clearly architect design in this, you can reference it https://creately.com/diagram/example/h4gr4x8d4/3-Tier%20Architecture
When you deploy the application in EC2.
You have Public DNS (IPv4) value for Ec2 ec2-xx-xx-xx-xx.compute-1.amazonaws.com. You will use this endpoint for WAR file.
If you do not assign Elastic ip for the EC2 Instance when you stop and start instance the ip address changed for Instance.
Based on your requirements you can leverage other services like Load Balancer and Route53.
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
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.
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.
I just installed MySQL in Amazon RDS, using its wizards. I selected the same security group my EC2 instance is using.
I tried to access this by Eclipse AWS toolkit. What I did is right clicking on the RDS instance and clicked on "Conenct". Then it asked for the password and tried to connect, but ended up with the below error.
Unable to connect to RDS database
java.lang.reflect.InvocationTargetException
I have seen number of posts regarding this without having a single solution.
I hope your machine IP is part of aws security rule. Please also check the respective ports are not blocked by your firewall..
You probably gave access to your ec2 security group, but not your local ip address. RDS does not use ec2 security groups, but I can open access to an ec2 security group.
I created an EBS instance including the RDS instance based on MySQL.
I have access to the EC2 instance using SSH via PuTTY and using the MySQL Workbench I've got access to the RDS instance as well and I can create tables and insert data in them.
I developed a Java application using Netbeans 7.3.1 and when I run the application locally while connecting to the MySQL instance on RDS the application shows the same problem although I can connect to MySQL from within Netbeans without a problem, ie I can connect to the database. But as soon as I deploy my simple application onto EBS and run the same application I get the error "Access denied for user ''#'' (using password: YES)"
I added the IP to the Security Group of my RDS instance as well as the EBS instance. Just to be sure.
Still I got the Access Denied error. The JDBC_CONNECTION_STRING environment variable I've set up is "jdbc:mysql://.cdydcnmtkkhw.us-west-1.rds.amazonaws.com:3306/ebdb?user=&password="
When I use any of the tools to connect to this database with that information all works, when I try to connect from my Java application running in Tomcat, I get the Access Denied message.
The Java call I'm using is:
private java.sql.Connection connect = DriverManager.getConnection(jdbcConnect);
This looks more like the stock standard cannot connect to mysql error and nothing really to do with EC2 as you have set up you security group.
See the mysql link. which explains about
SET PASSWORD FOR 'abe'#'host_name' = PASSWORD('eagle');