I'm attempting to reach my private Postgres database that is connected to a private linux instance. When I access it through terminal, I have to first SSH to the bastion instance and then using the same PEM file SSH into the private linux instance from where I can access the database. I wish to reach this database with python using sqlalchemy. I have read about SSH port forwarding but I'm having trouble. I've found this example, but I'm unclear where I enter the address of the private instance, I've tried using the address in the remote_bind_address but that threw and error.
could not translate host name to address
with SSHTunnelForwarder(
('xxx-x-xx-xx-xxx.us-west-2.compute.amazonaws.com'), """bastian server"""
ssh_username="buntu",
ssh_pkey="fourmm.pem",
remote_bind_address=('Address of private instance?', 22)
) as tunnel:
print("****SSH Tunnel Established****")
engine = create_engine(
"postgresql://postgres:XXXXXXXxxxxxxx@xxxx-xx.cluster-xxxxxx.us-wesr-.rds.amazonaws.com:5432/postgres",
echo=True, future=True)