1

How would I set up a tunnel using Python code that could replace this command?

ssh -N -L 3307:xxxxxx.rds.amazonaws.com:3306 [email protected] -i ~/.ssh/bastion_key.pem

1 Answer 1

1

You can use the sshtunnel library.

For example:

from sshtunnel import SSHTunnelForwarder

with SSHTunnelForwarder(
    ('XX.XXX.XX.XX', 22),
    ssh_username='ec2-user',
    ssh_pkey='~/.ssh/bastion_key.pem',
    remote_bind_address=('xxxxxx.rds.amazonaws.com', 3306),
    local_bind_address=('0.0.0.0', 3307)
) as tunnel:
    # do stuff with tunnel
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.