I'm trying to connect from my local machine to our AWS DocumentDB instance using pymongo. Our current setup is using a ssh tunnel on an ec2 instance which then connects to AWS DocumentDB. This part is working because I can connect via third party tooling to it. (e.g. Studio 3T - no issues creating users).
In each third party tooling I've uploaded the rds-combined-ca-bundle.pem file and I think this may be where I am getting stuck.
The tunnel works according to the logs on the bastion host.
I've tried several variations of the code below, but it just times out.
Currently using version 4.3.3 of pymongo.
Also, for additional information, I'm wanting to test this on my desktop but eventually move it to Lambda.
Any help is much appreciated!!
Current code-
import pymongo
import sshtunnel
global_pem_key="c:\\users\\user\\pathto\\rds-combined-ca-bundle.pem"
ssh_host = 'external IP'
ssh_username = 'sshUser'
database_username = 'Uname'
database_password = 'Pword'
database_name = 'dbname'
tunnel = sshtunnel.SSHTunnelForwarder(
(ssh_host, 22),
ssh_username=ssh_username,
ssh_pkey="c:\\users\\user\\path\\sshpemkey",
remote_bind_address=('127.0.0.1', 3306)
)
tunnel.start()
client=pymongo.MongoClient("mongodb://dbuname:dbpass@dbName.cluster-***.*-*-*.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false",
tlsInsecure=True,
directConnection=True,
tls=True,
tlsCAFile='c:\\users\\user\\\dpath\\rds-combined-ca-bundle.pem'
)
print(client.list_database_names())
tunnel.close()