Cannot connect to RDS by ssh - mysql

I created the RDS basically following the terraform example: https://www.terraform.io/intro/examples/index.html
I used existent VPC and when I create an instance in this VPC I can ssh using the SSH key file - cloudeng.pem
The MySQL terraform created the RDS with the endpoint demo-rds.abc.us-east-1.rds.amazonaws.com.
So, I am trying to set the connection by MySQL workbench.
Workbench requires the following:
SSH Hostname: not sure how to set, tried `172.31.96.233` from ping `endpoint dmo-rds.abc.us-east-1.rds.amazonaws.com`
SSH Username: ec2-user
SSH Key file – cloudeng.pem
MySQL Hostname: endpoint dbmonitor-rds.cmufislueksi.us-east-1.rds.amazonaws.com
MySQL Server port: 3306
Username: dbmonitor_user
Password: password
I am getting Tunnel Connection Error

I understand you question correctly you are trying to connect with RDS using SSH tunnel.
You need EC2 instance for tunnelling that is accessible from your machine and you able to ssh to EC2
EC2 able to communicate with RDS mean both should in same VPC
Before connecting to Workbench ssh tunnel I will recommend verifying SSH connection from the command line as it will give you more debug log.
ssh -i mykey.pem ec2-user#EC2_IP
Once you able to SSH to ec2 instance then you are good to go with MySQL workbench.

I wish to ssh into the RDS
You can't SSH into RDS. AWS manages RDS instances and does not allow access to them, except for connecting to the database endpoint.
However, you can establish ssh tunnel from your instance to the endpoint, not ssh from inside of the RDS instance:
How can I use an SSH tunnel and MySQL Workbench to connect to a private Amazon RDS MySQL DB instance that uses a public EC2 instance?

Related

Can't Connect to RDS mysql DB from Wordpress on Amazon linux EC2 Instance

I am getting Error establishing a database connection while trying to connect to mysql on Amazon RDS from my Wordpress instance.
Wordpress is on my AWS Linux EC2 Instance, both are on the same VPC, same Security Group allowing 3306 inbound rule, db credentials in wp-config is also correct.
I am able to connect to my mysql RDS instance while ssh with the following command and it connects fine:
mysql -h "endpoint url" -u "username" -p "password";
However, when accessing the EC2 EIP on the browser to setup my WP final configuration I get the error connecting DB.
Did you check your security group? Because you have to open the MySQL Port 3306.
When you are creating the RDS, it is important to create a new security group, like myRDSgroup, later you have to modify it by open the port 3306 in the source select the security group where your AWS EC2 is located.
Could you send your security group screenshot, please?

Connecting to MySQL RDS instance through AWS bastion host from a MySQL client

I'm trying to connect to a RDS instance from a MySQL Client tool. But the issue I found was it could only SSH to one machine (AWS bastion host). But how do I connect to the RDS instance internally thorugh the AWS bastion host?
Consider the machines A, B and C where,
A-> local machine
B-> AWS ec2-instance
C-> RDS instance
On making the machine B as a AWS bastion host, Is it possible to connect through SSH to RDS instance via the AWS bastion host (machine B) just by connecting to machine B from machine A?
i.e., on connecting through SSH to machine B from machine A, the machine B should automatically SSH and connect to the MySQL RDS instance (machine C).
As they suggested before, you need to connect by an ssh tunnel.
You can do it with mysql client, or from console:
ssh user#example.com -L 3307:{target_host}:3306 -N
Note: 3306 is the port where you set the tunnel for connect mysql client, you will use it again for run the client.
Then just run again mysql client from the tunnel:
mysql --host={target_host} --port=3306 -u user -p

AWS RDS (MySQL) Secure Connection

I have following aws resources an EC2 Instance(running on windows platform) and a AWS RDS MySQL(complied for linux).
I want to connect AWS RDS MySQL instance using SSL through MySQL client utilities like MySQL workbench or TOAD for MySQL.
My questions
Are SSL CA, CERT Key files and SSL Cipher information located on AWS RDS MySQL instance?
How to connect to AWS RDS MySQL to download these files.
Are these files are required for above scenario?
Can I use SSH Client to connect AWS RDS (MYSQL)?
I have seen blogs/post but there EC2 instance is LINUX based.
My understanding SSH is used to remotely connect Linux machines.
Is there anyother way to connect AWS RDS MySQL securly?
RDS server doesn't served SSH.
However, you can create a SSH tunnel to EC2 instance that permit to access the RDS instance. You may also enable compression within the connection using ssh tunnel. Quite useful if you want to upload/download large data set from RDS.
# E.g. EC2 instance = ec2servername
# Create a ssh tunnel to RDS , access through local port 5678
ssh -C -o CompressionLevel=9 -N -L 5678:<your-rds-fqdn>:3306 <ec2username>#ec2servername -i ec2_private_key.pem
# mysql client connection
mysql -u <rdsusername> -p <database name> -h 127.0.0.1 -P 5678
You can download the SSL certificates here: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html
You cannot SSH into an RDS instance as it is managed by AWS and you aren't given SSH access.
In addition to using SSL you should configure the Security Groups in your VPC such that only servers within your VPC can access the RDS instance.
If you are using MySQL workbench then its pretty straight forward. Steps
1. Click on new MySQL connection.
2. Give any Connection name for your reference
3. In hostname field, add the endpoint URL which you can get from AWS RDS console. (dont add :3306, its default)
4. In username field, add the username you had added while creating RDS instance.
5. Keep other params as it is and click on Test Connection.It will ask for password which you had added while creating RDS instance.
6. If all the input params are correct, you are connected to the database
You cannot SSH into an RDS instance as it is managed by AWS and you aren't given SSH access.
but we have an option to create a SSH tunnel to EC2 instance that permit to access the RDS instance.
i got reference from this video, thought it may help other connect AWS RDS Db instances from our local machine using an Amazon EC2 "SSH Tunnel"

What would prevent me from connecting to a MySQL server on AWS RDS from an AWS EC2 VM?

I have a MySQL RDS instance in AWS which has been set up properly.
I also have a Linux EC2 instance in AWS.
However, I can't connect to my RDS instance from the EC2 instance.
I can connect to the RDS instance from my own laptop, however.
I suspect it is one of four things
interface binding of the RDS instance - it is listening on the external interface but not on the internal one
firewall for the RDS instance - it is allowed connections from outside the AWS network but not from inside
firewall for the EC2 instance - it is not allowing connections to the RDS instance
name resolution on the EC2 instance - for some reason the name of the RDS instance is not resolving to the right IP address
However, I have checked all of these to the best of my knowledge, and they seem to be in order.
What should I be looking at?
Update 1: Following a question by #mbaird, I have checked that both the EC2 instance and the RDS instance are on the same VPC. What implications does that have?
Update 2: Following a question by the user #"Michael - sqlbot", when I say cannot connect, when running mysql at the command line, with
mysql --host=<my-hostname> --port=3306 --user=<user> --password=<password>
I can connect form my own laptop, but when I try connecting from my EC2 instance, it just sits there doing nothing. After a while, I get the message
ERROR 2003 (HY000): Can't connect to MySQL server on '<my-hostname>' (110)
Also, when trying to connect to it from my Java application server, I get the following in my stack trace
Caused by: 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.
...
Caused by: java.net.ConnectException: Connection timed out
Update 3: The DNS resolution is different depending on whether I am internal to AWS or external.
nslookup <my-hostname>
on my laptop results in an IP address 52.11.*.* range, while doing the same from my EC2 instance results in an IP address in the 172.31.*.* range.
If your EC2 Instance and RDS DB Instance are in different VPC, you might be using VPC peering to connect two VPCs. But in your case, both are in same VPC. That's good. Make sure RDS DB Instance are launched in private subnet and EC2 Instance are launched in public subnet.
To Connect RDS DB Instance in EC2 Instance
In RDS DB Instance security group, you need to open traffic for EC2 instance.
Click DB Security Group from RDS Dashboard. Click on Inbound tab. Edit button is used to add or remove rules from security group.
Add rule for EC2 Instance to access your database. Let's say, you have launched MySQL DB Engine in DB Instance. You need to open 3306 port for EC2 Instance. You can use Private IP of EC2 instance to connect with RDS DB Instance.
SSH into EC2 instance, install mysql-server package. You need to connect RDS DB Instance using mysql-server.
mysql --host=<my-hostname> --port=3306 --user=<user> --password=<password> command used to connect with RDS DB Instance.
To Connect RDS DB Instance in MySQL WorkBench
In MySQL WorkBench, click on Setup New Connection.
Give connection name. Choose Standard (TCP/IP) over SSH. You need to provide SSH hostname, username and keyfile as well as MySQL hostname, port, username and password.
SSH credentials is nothing as EC2 instance credentials. For Keyfile, you have to browse for KeyPair(.pem) file. In RDS Hostname, you have to provide endpoint which is available in RDS dashboard.
To verify connection, click on Test Connection button.
The reason you are choosing Standard (TCP/IP) over SSH is to connect RDS DB Instance through EC2 Instance. First, It will connect to an EC2 Instance and then access to RDS DB Instance because DB Instance doesn't have internet access and it is in Private Subnet.
Make sure in java web application, you mentioned RDS hostname, port, username and password are correct. No need to mention EC2 hostname in the application.

Unable to connect to MySQL AWS RDS instance from local MySQL

I have created an MySQL RDS instance with VPC. Now i am trying to connect to that RDS instance from my Ubuntu 12.04 machine using MySQL client by following code:
mysql -u uname -h test.c6tjb4nxvlri.us-west-2.rds.amazonaws.com -P 3306 -p
But i am getting this error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'test.c6tjb4nxvlri.us-west-2.rds.amazonaws.com' (110)
I searched about this error and everywhere solution came out like
Go to the Instances
Find the security group
Change the inbound rules of that security group by
Adding source of user machine public ip or
Set source ip as 0.0.0.0/16
I tried everything but still same error occures. Any explanations?
The problem was in subnet. Subnet that you created must be publicly accessible.
In On-premises MySQL Workbench, use TCP/IP SSH Tunneling option. Make sure you have EC2 instance endpoint and keypair file.
In SSH endpoint - add your EC2 instance endpoint and for SSH password, browse your keypair. Rest of configurations for MySQL. Like MySQL's endpoint, username, password, port and schema name.
Test your connection it will return success. If not, check RDS Security group. In Security group, you open MySQL port for all IP address. Try it! it will work. Once connection was success, all schema are visible in MySQL Workbench.
RDS DB instance need not to be in public subnet and it is not best practice to do. Always keep RDS DB instance in private subnet and open traffic for EC2 instance.
When you use TCP/IP SSH Tunneling, request traffic will send through EC2 instance to RDS DB instance.
HTH.