Created
October 22, 2018 00:32
-
-
Save jshahriddhi/9d53140dec7c17e63e22a0b5ab43f99f to your computer and use it in GitHub Desktop.
Revisions
-
jshahriddhi created this gist
Oct 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ from sshtunnel import SSHTunnelForwarder import pymysql with SSHTunnelForwarder( ('ec2-52-202-194-76.public-ec2-instance.amazonaws.com'), ssh_username="ec2-user", ssh_pkey="~/ssh-tunnel-rds.pem", remote_bind_address=('private-rds-instance.ckfkidfytpr4.us-east-1.rds.amazonaws.com', 3306) ) as tunnel: print("****SSH Tunnel Established****") db = pymysql.connect( host='127.0.0.1', user="rdsuser", password="rdspassword", port=tunnel.local_bind_port ) # Run sample query in the database to validate connection try: # Print all the databases with db.cursor() as cur: cur.execute('SHOW DATABASES') for r in cur: print(r) finally: db.close() print("YAYY!!")