The error I receive :
"errorMessage": "dev-pe-0.vvwclmg.mongodb.net:27017: [Errno -5] No address associated with hostname, Timeout: 30s, Topology Description: <TopologyDescription id: 64207dd34375c6ac1adb4bf4, topology_type: Unknown, servers: [<ServerDescription ('dev-pe-0.vvwclmg.mongodb.net', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('dev-pe-0.vvwclmg.mongodb.net:27017: [Errno -5] No address associated with hostname')>]>",
"errorType": "ServerSelectionTimeoutError"
Resources I’ve set up :
- VPC with 2 private subnets, and security group that allows all outbound access
- Lambda function running in this VPC and the 2 private subnets, and the security group
- MongoDB serverless instance with 0.0.0.0/0 access
- Added ARN of the Lambda role to Database Access in MongoDB with permission
readWriteAnyDatabase
- Private endpoint for MongoDB (followed https://www.mongodb.com/docs/atlas/security-serverless-private-endpoint/)
- Endpoint in AWS created with
create-vpc-endpoint
call that uses the endpoint service created above
How I’m calling MongoDB (code snippet) :
import pymongo
client = pymongo.MongoClient(os.getenv("MONGODB_CONNECTION_URI"))
def handler(event, context):
data = some-data-to-insert
db = client.myDatabase
db.myCollection.insert_many(data)
where MONGODB_CONNECTION_URI
= mongodb://dev-pe-0.vvwclmg.mongodb.net/?authMechanism=MONGODB-AWS
This seems to be a connectivity issue - what am I missing?