unable to connect pymongo to mongodb cluster from document DB AWS

I have created a mongoDB cluster in documentDB. I tried connecting to the cluster from my local machine through mongoclient from pymongo.

cluster endpoint=mongooi.cluster-abcdefghij.us-east-2.docdb.amazonaws.com

client=pymongo.Mongoclient("mongodb://USER:PASSWORD@mongooi.cluster-abcdefghij.us-east-2.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false*")

print(client.database_names())

I get ServerSelectionTimeoutError: mongooi.cluster-abcdefghij.us-east-2.docdb.amazonaws.com:27017: timed out

Upvotes: 2

Views: 1513

Answers (1)

herbertgoto
herbertgoto

Reputation: 359

DocumentDB clusters are network-secure by default, so the endpoint you get cannot be reach directly from your local machine. For that, you need to have a tunnel via an EC2 server. You can find guidelines in the following link:

https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html

Upvotes: 4

Related Questions