Paolo Sanchi
Paolo Sanchi

Reputation: 821

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).

Upvotes: 11

Views: 7543

Answers (2)

Leslie McCutcheon
Leslie McCutcheon

Reputation: 231

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/

Upvotes: 23

Jay Gordon
Jay Gordon

Reputation: 367

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

Upvotes: 1

Related Questions