This solution uses SSH Tunnel. Tunnel will port forward your connection from ec2 instance to rds. Not sure if any ec2 instance will work, I checked only for ElasticBeanstalk stack with attached rds instance. I’ll explain how to setup connection on PgAdmin4 and IntelliJ.
Before Anything…
Try connecting to your ec2-instance:
ssh -i your.pem [email protected]
If connection doesn’t go through, you might want to check my other post for connecting to ec2.
Configure PgAdmin4
Open pgadmin4, add a new server. Give it a name, click on the Connection tab. Fill the fields with your connection details for rds (host, user, pass). Leave the maintenance database to be postgres.

Click on SSH Tunnel, and fill tunnel host, username and identity file.

Click on Save, you should be able to connect to your server and see ebdb
database in list.
Configure IntelliJ IDEA
Add a new datasource – Click on Database tab -> + sign -> Datasource -> PostgreSQL. Like shown in the screenshot:

Fill the fields with your connection details for rds (host, user, pass). Database will probably be ebdb
.Click on SSH/SSL, check Use SSH tunnel, add a new configuration by clicking three dots on the right. Fill tunnel host, username and identity file.

Click on Apply, update driver if you need to, and test the connection.