How to Connect with Private RDS using EC2
Today my colleague gave me a task like checking his data from RDS (Relational Database Service) from AWS which is not publicly accessible.
so to resolve this I needed to check, what kind of database he was using, at last, I found that he was using a Postgres database.
After knowing that I just created an ec2 instance in the same VPC network and updated the package manager as I’m using ubuntu OS in my instance I used a command like
sudo apt update
sudo apt install postgresql-client
then I put a command to install Postgres in my instance. Because to connect the RDS we need to install this in our EC2 instance. As per our rds, it was a Postgres database so we need to install Postgres on it. Then only we can connect with that RDS.
Moving on now we need to alter the existing sg (Security group) of our ec2 instance and rds then only they can communicate with each other.
in this image you can see that we just enabled the port of PostgreSQL in the EC2 instance.
In addition, do changes in RDS sg as well,
Here you can see that I have added the sg of the ec2 instance in RDS. Because by adding the sg of the ec2 instance to the sg of RDS we get the traffic from the ec2 instance seamlessly.
After completing all sg configurations, use this command to connect with RDS.
psql -h <RDS-endpoint> -U <username>
After that it demands a password then I entered the password.
Now we successfully entered into the rds and using the \l command means we can list the database to find the records in the database.
Hope this is helpful to you guys, For more of this kind of content do follow, it motivates me to do more!!
Taaraaaaaaa!!