I am creating a javascript meteor app from my localhost, but I would like my database to be stored on a separate aws server.
I am new to MongoDB and aws. I am wondering how I would go about connecting to my database from my local host?
That's as simple as starting your Meteor app with MONGO_URL
env variable set to point to the Mongo instance running on your AWS machine.
Assuming you have already opened port 27017 on remote machine:
MONGO_URL=mongodb://addresshere.compute-1.amazonaws.com:27017/yourdbname meteor
In addition to configuring the application to connect to remote MongoDB, as mentioned in other answers, it is also necessary to make sure the server is accessible from your network.
There are different ways to access the network resource on AWS:
Change the security group configuration for EC2 instance - this acts as a firewall - and allow access to port 27017. If you only need to access it from your machine, there is an option to allow access from your current IP.
Use ssh tunnel to connect to the instance and have that port tunneled locally, something like ssh aws-host -L 27017:localhost:27017
or, if you are connecting through the different instance ssh aws-host -L 2017:target.mongo.host.amazonaws.com:27017
.
There is a good presentation on this topic - The Black Magic Of SSH / SSH Can Do That?.
Use VPN on AWS and connect to AWS network via VPN (making resources inside your AWS network available locally).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With