Can't connect to RDS from AWS EC2 - amazon-web-services

I'm new to AWS and I'm having trouble connecting to my RDS instance from my EC2 instance. I think both are sitting within the same VPC. I can use SSH2 from putty to connect to my EC2 instance and I can use eclipse to connect to my RDS instance. However, I can't see to connect to the RDS from the EC2. When I try the following command:
ec2 command prompt> mysql -h endpoint -P 3306 -u user -p password
I get the following error:
Enter password:
ERROR 1049 (42000): Unknown database 'password'
Any ideas what I'm doing wrong? Also, why is it asking me for my password again? I've already specified it in my connection string.
Any help would be appreciated - thanks!

Okay - I was able to figure out what was wrong. It seems that I should be using the following to connect to the RDS:
mysql -u username -p -h endpoint databaseName
This prompts me to enter in my password, which then connects me to my database above in the RDS instance that I have set up. Evidently, you have to specify the database that you want to connect to and the port number is optional. I was able to connect both with it and without it. The documentation on AWS that I've read has never actually had the database name, which is what was throwing me off. Hope this can help someone else.

Related

Unable to Connect AWS RDS from SQL Developer

I just need help here,
I'm just getting started into AWS RDS, I have web application and I have deployed into AWS Through AWS EBS
and now I wanted to connect my DB, for that I attached RDS to my application in beanstalk. When testing the connection, I am Getting this error
This is my ENDPOINT:
Here are my RDS DB Configuration:
and SID is:
please help me sort this, I got stuck here from 2 days.
Thank You.... :)
Please, in your connection setup in SQL Developer, in the Hostname field, just remove the literal :3306 at the end of your hostname string: this value is in fact the port in which the database is listening.
In order to complete your connection setup, enter the value 3306 in the Port field instead of the 1521 you indicated in your image.

Unable to connect to AWS Documentdb using MongoDB Compass. No option to pass sslInvalidHostName

AWS DocumentDB is a relatively new service we're trying to migrate to. To connect from outside of the VPC, you have to create a tunnel to an existing instance.
For example:
ssh -i "ec2Access.pem" -L 27017:sample-cluster.cluster-cu52jq5kfddg.us-east-1.docdb.amazonaws.com:27017 ubuntu#ec2-34-229-221-164.compute-1.amazonaws.com -N
And then you can connect from mongo shell with:
mongo --sslAllowInvalidHostnames --ssl --sslCAFile rds-combined-ca-bundle.pem --username <yourUsername> --password <yourPassword>
You can see this info at: https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html
I'm actually able to get a shell into document db following the above instructions but I can not connect to it using MongoDB compass. We need to be able to do this for our non-developer team.
I have done this using only MongoDB Compass (Community, v. 1.16.4), without creation of a tunnel via external tools.
Firstly, download AWS's certificate from:
https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem.
I have got this link from:
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html
Also make sure that you have an access to your DocDB cluster from the EC2 instance.
To do it look into security groups settings specified for your DocDB cluster.
Given that you are able to get the access using mongo shell, you should have it.
Then on the connection screen in MongoDB Compass specify the following (your credentials used as an example):
Hostname: sample-cluster.cluster-cu52jq5kfddg.us-east-1.docdb.amazonaws.com
Port: 27017
Authentication: Username/Password
Username: YourDocDBUsername
Password: YourDocDBUserPassword
SSL: Server validation
Certificate Authority: (select downloaded rds-combined-ca-bundle.pem)
SSH Tunnel: Use identity file
SSH Hostname: ec2-34-229-221-164.compute-1.amazonaws.com
SSH Tunnel Port: 22
SSH Username: ubuntu
SSH Identity File: ec2Access.pem
I similarly was able to connect to my tunneled DocumentDB instance via mongosh but not with MongoDB Compass. I noticed that mongosh outputs the connection string so I copied that in Compass and it worked.
mongodb://<credentials>#localhost:27017/?directConnection=true&tls=true&tlsAllowInvalidHostnames=true&tlsCAFile=<path_to_pem>
It looks like the part that I was missing was
directConnection=true

Tunneling to redshift cluster

I am new to redshift. Currently, I am able to create a redshift cluster and connect it through SQL Workbench but I am looking forward to tunnel my redshift cluster doing ssh from my MAC terminal. I did some research and able to create an ec2 instance with same VPC ID and subnet group which I am using to create my Redshift cluster with. I have already installed psql on my ec2 instance as well. I am not able to understand where I am going wrong when I use psql command to connect to redshift :
psql -h my redshift endpoint -p 5439 -d database name -U user -c " my query "
it gives me error psql: could not translate host name "my redshift endpoint" to address: Name or service not known
The first step is to tunnel to the EC2 instance using ssh, with a command that forwards a local port to a remote port:
ssh -i KEYPAIR.pem -L 5439:REDSHIFT-ENDPOINT:5439 ec2-user#EC2-PUBLIC-IP
Where:
KEYPAIR.pem should be the name of the keypair used to access the EC2 instance
REDSHIFT-ENDPOINT is the DNS name of the Redshift endpoint
EC2-PUBLIC-IP is the IP address of the EC2 instance
This command says:
Create an ssh connection using the keypair
Forward any traffic sent to local port 5439 to the remote machine, then have the remote machine send that traffic to REDSHIFT-ENDPOINT:5439 (substitute your endpoint for REDSHIFT-ENDPOINT)
Then, you can connect to Redshift on localhost:5439 as if it were running on your own computer. That traffic will be sent to the remote machine, which will send it to REDSHIFT-ENDPOINT:5439.
For example, if you want to use psql to connect to Redshift, use:
psql -h localhost -p 5439 -U <username>
try psql -h localhost -p 5439 -d -U -c " my query " or psql -p 5439 -d -U -c " my query ", you can't use switch -h without an argument, which is localhost by default if you don't use it
Thanks John Rotenstein on giving me insight, I was actually missing the Inbound rule associated with my security group to only allow traffic coming from redshift private IP. Both of my ec2 instance and redshift were in the same VPC so was supposed to use private instead of public IP. Also forgot to put ssh public key of redshift in the ec2 authorized_key file. Once I did that it worked.

Coldfusion Administrator - connect to data source via SSH

I'd like to configure my coldfusion instance to connect to a MySQL database over SSH but I'm not really sure how.
Basically, I have an EC2 instance in the same region as an RDS instance for the purposes of a development environment. I want to hook into my Production RDS instance so that I can do some tests with production data for a specific feature I'm working on but it's turning out to be quite a bit of trouble since it's in a different region.
I'd rather not alter AWS in any way to achieve this. So far the only thing I could think to try was to SSH into my EC2 instance and setup a tunnel like this
ssh -i ./mykey.pem -N -L 3306:localhost:3306 username#host_ip
When I enter this command I don't see any output but I assume it is running, however when I try to access my EC2 instance via the web I see this error: Timed out trying to establish connection
Is there something wrong with my setup? I know I have the correct key, credentials, and host but I am a bit confused on the ports. I figured my coldfusion admin panel is looking on port 3306 and my database is served on port 3306 so 3306:localhost:3306 seems correct to me but obviously I am doing something wrong.

What should be my host name in putty configuration for setting up SSH server?

I am setting up a node.js server on AWS EC2 using putty configurations.There I found to configure putty.I stuck filling the hostname of EC2 in putty.What will be the hostname can anyone Help?
screenshot of putty config :
Note: I have an EC2 instance launched which I have connect with this.
You can give the public ip of your ec2 instance there. which you can find in the aws management console. Attached is the screen-shot for the same.
Let me know if you are not able to connect with this method.
After generating the key .ppk go to SSH-->Auth-->Browse the .ppk key,
save it and load then open.
Log in with ec2-user.
If you want to give a try, we developed an alternative CLI for AWS that makes this much easier: awless.
It should work on Windows too and with awless, you don't need to set either your IP address nor username, just awless ssh i-1234 or awless ssh my-instance-name.
Note that you may also need to add: -i path/to/your/key.pem if the key was not created with awless.