question

AhsanHabib-1895 avatar image
0 Votes"
AhsanHabib-1895 asked bhouser published

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, 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, as a single Zone may 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 my question is what other options do I have? Is there any way to connect them using some managed identity or Authentication/Authorization approach using Azure AD or something like that? Is Federated Authentication fits for such a case?

azure-functions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JayaC-MSFT avatar image
0 Votes"
JayaC-MSFT answered bhouser published

Hello @AhsanHabib-1895, In case of the first option I would recommend you to consider using service tags : https://docs.microsoft.com/en-us/azure/virtual-network/service-tags-overview#available-service-tags

Also if you need static, dedicated IP addresses, we recommend App Service Environments (the Isolated tier of App Service plans). { Again this could be an expensive approach as mentioned in point no.2 }
https://docs.microsoft.com/en-us/azure/azure-functions/ip-addresses#dedicated-ip-addresses

For ref : https://www.mongodb.com/blog/post/how-to-integrate-azure-functions-with-mongodb

https://thecodebarbarian.com/getting-started-with-azure-functions-and-mongodb.html

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JayaC-MSFT - Option using service tags : https://docs.microsoft.com/en-us/azure/virtual-network/service-tags-overview#available-service-tags can be used in case of only vnet integration and cannot be used in consumption tier right ?

0 Votes 0 ·
bhouser avatar image bhouser NehaOberoi-1041 ·

Have you found a way to make this work with the consumption tier azure functions?

0 Votes 0 ·