Unable to access Amazon RDS using Eclipse - java

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.

Related

Can't connect to a database on Amazon RDS from Amazon EC2 ubuntu 16.04 image

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

Accessing Google Cloud VM Instance Tomcat using External IP

I am trying to access my Tomcat HomePage which is inside my Google Cloud VM Instance with External IP address 35.189.85.127 and Internal IP 10.154.0.2. On my local machine, in my browser I tried http://35.189.85.127 and http://35.189.85.127:8080 but got error
The connection has timed out. The server at 35.189.85.127 is taking too long to respond.
I have seen all the questions and replies on stackoverflow regarding this question but still I found no clear solution.
The steps that I've done so far:
I have setup a Google Cloud VM instance in Compute Engine. I am using Windows Server 2016 as the image.
Using RDP I log on to Windows Server.
I successfully installed Java 1.7 and Tomcat 7 on Windows Server.
I tested Java and Tomcat 7, both are working fine i.e. I open browser and type localhost:8080 and it shows Tomcat HomePage.
I replaced localhost with my VM Instance Internal IP i.e. 10.154.0.2:8080 and it again correctly shows Tomcat HomePage.
Now I try to access Tomcat HomePage using my VM Instance External IP (Static) 35.189.85.127 but in my browser I get error
The connection has timed out. The server at 35.189.85.127 is taking too long to respond.
Faced the same issue today.
Noticed from your question that you're using an Windows environment.
On Windows
Be sure that the Windows Firewall is properly configured to allow traffic under the ports you need (or deactivate it).
On GCP
Under "VPC Network/Firewall Rules", create a new firewall rule and configure as below:
Firewall Rule Parameters (image)
Or, you have the option to check the "Allow HTTP traffic" option under the Instance Configuration menu and edit Tomcat's server.xml to startup at port 80, as described here:
Change Tomcat Port Tutorial # StackOverflow
Option1: If it's just tomcat. GCP offers a click to launch Tomcat instance with an external IP. You can SSH and also have a temp tomcat username and password to manage any of your deployments.
https://console.cloud.google.com/launcher/details/click-to-deploy-images/tomcat
Option 2:
If you wish to have a Google Cloud VM instance in Compute Engine.
You will need to setup security groups and assign it to your instance.
Eg. Define rules to Open Tomcat port 8080(or any) externally / range. Assign that group/rule to your VM instance.
There are many options available, it all depends on how you wish to organize things. You could create a VPC and add your instances there or keep them under the same subnet or have them accessible externally etc.

Communication between Android and EC2 with RDS

I have an EC2 instance on AWS configured with Apache tomcat 8 and java.
Following some tutorials from here, I can create one .war of my Web Service in eclipse and put it inside webapps folder of tomcat in my EC2 instance.
I am able to access this services from the IP address of EC2 with the specific port and .war file name.
For example:
IPADDRESS:8080/MyApplication.
And everything seems to work fine, I can open the services and see the wsdl files. My Web Service (in .war file) is configured for make a connection with a RDS instance from amazon.
The connection itself is ok, I tested in localhost a direct connection with RDS from Android.
But, when I try to connect with services that I put in EC2 (from there
the connection with my RDS is created) from Android, no data returns and I get a Null Pointer.
The link that I used to make a connection with EC2 from Android is the Public IP of EC2 and the port (8080), followed by the specific path of wsdl file.
For example:
http://99.999.999.99:8080/MyApplication/services/SomeServiceName?wsdl
I am using the KSOAP library to consume web service on Android side and I
have no idea of the reason that I don't get data from EC2 instance.
All methods in the web service and the comsumption in Android works fine, I tested all in local host.
I tested all my methods of web service using SOAP UI, and all of them is working
For test the RDS instance that contains my DB, I run the web service in localhost with tomcat 8 and the communication Android -> My PC (localhost) -> RDS instance (My DB) is working.
The problem are when I try to change the communication line from:
*Android -> My PC (localhost) -> RDS instance (My DB)*
TO:
*Android -> EC2 instance -> RDS instance (My DB)*
Again, in EC2 I make the deploy of my web service.
I use the same security group for RDS and EC2:
Inbound rules:
http://i.stack.imgur.com/RUdyl.png
Outbound rules:
http://i.stack.imgur.com/W4gLc.png
I finally solved the problem.
I did the following:
I connected to my ECB2 instance and open the tomcat 8 log, so I saw that the error was ClassNotFoundException, related to Postgres (my engine DB).
I opened my web service eclipse project and saw this (stupid) error:
The .jar postgres driver was in that lib folder:
Instead of that folder:
So, basically, when I did the deploy of my Web service in EC2 instance the postgres driver does not go together.
Thanks for the help, I hope that helps someone else.

Amazon RDS instance in EBS: Access Denied when trying from Java application in Tomcat

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');

EC2 to RDS connection fails but localhost to RDS works

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.

Categories