How to use python to connect to Postgresql RDS in Private subnet

Viewed 20

I have my RDS(Postgresql) database in Private subnet. I want to query this db using a Python Program Is this possible ? I have a bastion running SSM and I can easily connect to the bastion without any keys and then connect to the DB. Is there a way of doing port forwarding in a python program ?

THANKS

2 Answers

I followed this article -

https://aws.amazon.com/blogs/aws/new-port-forwarding-using-aws-system-manager-sessions-manager/

I am able to start the session with my ec2 - but the session is waiting for connections -

aws ssm start-session --target $INSTANCE_ID \
                       --document-name AWS-StartPortForwardingSession \
                       --parameters '{"portNumber":["80"],"localPortNumber":["9999"]}'

Starting session with SessionId: <cccccc-12cdddd> 
Port 9999 opened for sessionId <fffdggdgggg> 
Waiting for connections...

How can I now run , starting another terminal is not helping

psql -h <> .....
Related