How to connect Azure Function with MongoDB Atlas

Here is my scenario: My Database is on MongoDB Atlas. I need to access Atlas from Azure Function(Dynamic/Consumption Plan) and App Service. In doing so, I am facing A timeout issue. I know, that this is because I have to whitelist outbound IP addresses of Azure Function and App Service Plan in Atlas. But Azure Function(with Consumption Plan) and App Service update their outbound IP addresses during the autoscaling process. Now there are 2 solutions I can think of:

  1. Whitelist all the IP addresses of an Azure Region/Zone. But this is not an ideal approach at all, as a single region could have many(500~1000 or more) IP addresses.
  2. Using the VPC peering. I guess we may connect Azure and Atlas through VNET. However, to do that, I need to connect the Azure function and App Service to Vnet first. The problem is VNET Integration with these services is a very expensive approach.

So now my question is what other options do I have? Is there any way to connect them using some Authentication/Authorization approach using Azure AD or something like this? Is Federated Authentication fits for such a case?

Hi @Ahsan_Habib,

Consider looking into azure private link :

This should allow you to connect azure service through a private link connection…

Thanks
Pavel

Hi Ahshan,

Did you get this working? I believe you would need to use an Azure Function Premium Plan (Azure Functions Premium plan | Microsoft Learn) to take advantage of private endpoints. The alternative would be to leverage public IP (I don’t believe Azure Functions use a static public IP so you’d need to essentially add 0.0.0.0/0 to the Atlas IP Access List).

Cheers
-Andrew