Connecting Python to a Database through SSH and SQLAlchemy

3

My current connection configuration is as follow, this is for redshift db

con=('postgresql://username:password@hostname:port/databasename')
    server = SSHTunnelForwarder(
        ('ssh host', 22),
        ssh_username="-",
        ssh_password="-",
        remote_bind_address=('db host', port)
        )

    server.start()
    local_port = str(server.local_bind_port)
    engine = sa.create_engine(con)

    ######## Reaches here then times out when reading the table
    df_read = pd.read_sql_table('tablename',engine)

However, the redshift database also has an SSH, which might be affecting the connection? It creates the engine but when reading the SQL in pd.read_sql_query I reach this error.

 (psycopg2.OperationalError) could not connect to server: Connection timed out (0x0000274C/10060)
    Is the server running on host "xxx" (xxx) and accepting
    TCP/IP connections on port xxx?

(Background on this error at: http://sqlalche.me/e/e3q8)
python
pandas
amazon-redshift
asked on Stack Overflow May 19, 2020 by MF DOOM • edited May 20, 2020 by MF DOOM

1 Answer

0

You cannot SSH into a Redshift cluster but you can use SSL to secure the connection.

answered on Stack Overflow May 21, 2020 by Joe Harris

User contributions licensed under CC BY-SA 3.0