Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to MongoDB Atlas cluster from an Azure App Service

I have a web app on Azure that connect to a MongoDB cluster hosted on Atlas (cloud.mongodb.com).

I'd like to use Atlas so I don't have to care about MongoDb configurations. The issue is that I get a timeout connecting my cluster. I have to set the app service ip in my mongo cluster whitelist, but If I try to download the page http://www.whatsmyip.org/ I get every time a different IP.

On the azure panel I've tried everything, set a VNET integration, set an ASE, a gateway. I really don't know how to expose the public IP.

However I have a VM that can query the mongo cluster, it has a Network interface with a public ip and a nsg (firewall).

like image 619
Paolo Sanchi Avatar asked Nov 09 '16 21:11

Paolo Sanchi


2 Answers

To expand Paolo's answer as it wasn't too clear and I had to do some extra research.

In the Azure portal, select your App Service and scroll down to the Settings section in the menu (headed by overview) and select properties.

Scroll down until you find the Outbound IP Addresses. These are the ones you will want to add to your whitelist in Atlas.

Useful Links: https://blogs.msdn.microsoft.com/waws/2017/02/01/how-do-i-determine-the-outbound-ip-addresses-of-my-azure-app-service/

like image 107
Leslie McCutcheon Avatar answered Sep 19 '22 05:09

Leslie McCutcheon


You can whitelist 0.0.0.0/0 and then rely on user authentication. Alternatively, you can use AWS as an alternative to Azure and use VPC peering.

https://www.mongodb.com/blog/post/introducing-vpc-peering-for-mongodb-atlas

like image 36
Jay Gordon Avatar answered Sep 20 '22 05:09

Jay Gordon