'Motor/PyMongo connection timeout with AWS DocumentDB

I have used Python's Motor library to connect to an AWS DocumentDB (MongoDB) instance. Motor uses PyMongo behind the scenes.

This was all working fine, but suddenly I have been getting a connection timeout anytime I attempt to do anything that requires a database operation:

pymongo.errors.ServerSelectionTimeoutError: aws-documentdb-endpoint:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 628376f4a53a913de7752368, topology_type: Single, servers: [<ServerDescription ('aws-documentdb-endpoint', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('aws-documentdb-endpoint:27017: timed out')>]>

This is how I am creating the connection, which has worked fine for weeks, but now gives this timeout error every time:

from motor.motor_asyncio import AsyncIOMotorClient

client = AsyncIOMotorClient(
    host=os.environ["MONGO_URI"], 
    ssl=True, 
    ssl_cert_reqs=ssl.CERT_NONE, 
    ssl_ca_certs=os.path.join(os.environ["ROOT_DIR"], "cert", "aws", "rds-combined-ca-bundle.pem")
)

I have no idea what is going wrong since this has been working fine for so long, but suddenly is not even thought I don't think I've made any changes to this part of the code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source