I am running the following code to send some files via SFTP from GCP to a server on AWS
import paramiko
import os
from airflow.contrib.hooks.ssh_hook import SSHHook
hook = SSHHook(remote_host="host.amazonaws.com",
username="username",
password="password")
hook.pkey = paramiko.RSAKey.from_private_key_file("keyfile")
conn_id = hook.get_conn().open_sftp()
When I run it locally on my computer evrything works and the SFTP connection is established. As soon as I move it to GCP and run as a task in Cloud Composer I get the following error:
WARNING - Remote Identification Change is not verified. This wont protect against Man-In-The-Middle attacks\n[2021-12-23 16:48:07,391] {ssh_hook.py:171} WARNING - No Host Key Verification. This wont protect against Man-In-The-Middle attacks\nTraceback (most recent call last):\n File "/tmp/venva41v8tku/script.py", line 29, in <module>\n res = make_sftp(*args, **kwargs)\n File "/tmp/venva41v8tku/script.py", line 27, in make_sftp\n conn_id = hook.get_conn()\n File "/usr/local/lib/airflow/airflow/contrib/hooks/ssh_hook.py", line 194, in get_conn\n client.connect(**connect_kwargs)\n File "/opt/python3.6/lib/python3.6/site-packages/paramiko/client.py", line 412, in connect\n server_key = t.get_remote_server_key()\n File "/opt/python3.6/lib/python3.6/site-packages/paramiko/transport.py", line 834, in get_remote_server_key\n raise SSHException("No existing session")\nparamiko.ssh_exception.SSHException: No existing session\n'
How can I get around this? Thanks!