How to Connect with Private RDS using EC2

Gerlyn M ☁️☸️
3 min readMar 16, 2023

--

Today my colleague gave me a task like checking his data from RDS (Relational Database Service) from AWS which is not publicly accessible.

RDS which are in private

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.

Security Group of Ec2 instance

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,

Security Group of RDS

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.

Connecting with RDS using EC2

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!!

--

--

Gerlyn M ☁️☸️
Gerlyn M ☁️☸️

Written by Gerlyn M ☁️☸️

As a self-taught DevOps engineer, I know the struggle of looking for a DevOps project to practice. So I'm here to help you all with new project ideas as a blog.

No responses yet