mongodbamazon-web-servicesdevopsamazon-vpcmongodb-atlas

Why Should I Encapsulate MongoDB Atlas in a AWS EC2 Cluster Instead of Connecting From My App via URL?


I'm building my first app from scratch, and I've decided to use MongoDB as the main DB. I've set up a MongoDBAtlas Instance, along with my Python app in AWS ElasticBeanstalk and with Docker. Now I'm trying to connect the app to MongoDBAtlas, so looked up some tutorials, and found one that actually set Peer connecting on the MongoDBAtlas Instance, and then deploys that instance to a new AWS EC2 Cluster, which ElasticBeanstalk accesses via VPC/Security Group rules.

Why is the tutorial teaching all of that AWS stuff for MongoDBAtlas, when I can just add the following URL access in my Python app?

client = MongoClient("mongodb+srv://<username>:<password>@trialcluster.mongodb.net")

I could just make different DBs per environment and have the connection URL change accordingly using env variables, no?


Solution

  • You can connect directly and that will work fine. Its more secure to connect via a VPC (virtual private connection) as both your application and the database and secured from outside interference. For a first app its not really necessary (neither is Beanstalk or Docker for that matter).

    You could also just run this app from your desktop as long as you white list your IP address in Atlas.