Azure functions unable to connect with Mongo Db Atlas M10

I setup an Azure functions and Mongo DB cluster to POC moving from on premise to Mongo DB Atlas platform.

I am able to access the mongo DB Atlas from developer box but not when I deploy to production Azure functions.

I saw several entry around the same error I got:
“A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 …”

I am using the latest Mongo DB Driver 2.12.0 and here is the format of connection string:
mongodb+srv://username:password@devatlassearch.jsqnn.mongodb.net/Integra?connect=replicaSet&retryWrites=true&w=majority&connectTimeoutMS=360000&socketTimeoutMs=360000

None of this seems to fix the issue connecting from Azure serverless functions. Any idea how to properly connect to Mongo Db Atlas from Azure serverless functions?

Hi Toga,

Is it possible that the dynamic Azure function IP is not on the Atlas IP Access List? If this is the issue, please note that Azure does not support having Functions connect via peering over a private IP: they do offer this workaround here Frequently asked questions about networking in Azure Functions | Microsoft Learn

Another option is to add to your IP Access List all IPs but if you do so it’s important to ensure you’re governing your database credentials appropriately.

-Andrew

Hi Andrew, I guess i prefer to let all IPs in however can you recommend a guidance to increase security for the database credentials.

If you use Vault then our secrets engine integration could be a great fit: MongoDB Atlas - Secrets Engines | Vault | HashiCorp Developer