How to interface Mongodb database with web application running on AWS EC2 instance - mongodb

I have installed Mongodb 3.0 database instance on AWS EC2 using AWS CloudFormation.
I have following 2 queries :-
During the installation, I chose the instance type as 't2.micro'
and if I'm not wrong, this should be covered up under AWS Free-Tier
usage for evaluation purpose. But may I know where exactly, I can
see and confirm that my instance is running under free-tier usage?
I have deployed a web application too using Elastic Beanstalk
services and it is running fine with one of the EC2 instances. I can
test my application on cloud very well with static data (means no DB
interface yet). I want to open the port between my Web App on 1 EC2
instance and MongoDB (which I installed recently) running on another
EC2 instance. Can somebody advise on this?
Thank you

Related

Where does MongoDB Atlas fit in my nodejs app?

I have an express app using MongoDB up and running locally. I am looking at options to deploy and wasn't clear on how MongoDB atlas fit in. I planning on just deploying the express app and database to an ec2 instance. Is that alright? Or do I need a separate instance for mongo to run on? MongoDB Atlas offers M2, M5, M10 etc. as options for nodes. I am very new at backend and want to know if those would be separate from my EC2 instance or if those would be my EC2 instance running my express app for clients to connect to as well.
Mongo Atlas is a standalone hosted MongoDB instance. It's a separate server, or typically a cluster of several servers, that only runs MongoDB. You'd run your Express app on an EC2 instance and have it talk over the network to the Mongo Atlas instance on another server.
The advantage is that you don't have to worry about installing or handholding Mongo, about configuring a redundant Mongo cluster, about upgrades or backups. Generally, separating the database server from the application server also means easier longterm maintenance of both. If your Express server doesn't store any data itself, then it is entirely disposable in case of emergencies, while you can be assured* that the critical data stored in your database is well cared for.
* As far as your contract with Atlas stipulates that the data is being cared for…

AWS + Elastic Beanstalk + MongoDB

I am trying to setup my microservices architecture using AWS Elastic Beanstalk and Docker. That is very easy to do, but when I launch the environment, it launches into the default VPC, thus giving public IP's to the instances. Right now, that's not too much of a concern.
What I am having a problem with is how to set up the MongoDB architecture. I have read: recommended way to install mongodb on elastic beanstalk but still remain unsure on how to set this up.
So far I have tried:
Using the CloudFormation template from AWS here: http://docs.aws.amazon.com/quickstart/latest/mongodb/step2b.html to launch a primary with 2 replica node setup into the default VPC, but this gives and assigns public access to the Mongo nodes. I also am not sure how to connect my application since this does not add a NAT instance - do I simply connect directly to the primary node? In case of failure for this node, will the secondary node's IP become the same as that of the primary node so that all connections remain consistent? Or do I need to add my own NAT instance?
I have also tried launching MongoDB into its own VPC (https://docs.aws.amazon.com/quickstart/latest/mongodb/step2a.html) and giving access via the NAT, but this means having two different VPCs (one for my EB instances and one for the MongoDB). In this case would I connect to the NAT from my EB VPC in order to route requests to the databases?
I have also tried launching a new VPC for the MongoDB architecture first and then trying to launch EB into this VPC. For some reason, the load balancing setup won't let me add into the subnets, giving me the error: "Custom Availability Zones option not supported for VPC environments".
I am trying to launch all this in us-west-1. It's been two days now and I have no idea where to go or what the right way is to tackle this issue. I want the databases to be private (no public access) with a NAT gateway, so ideally my third method seems what I want, but I cannot seem to add the new EB instances/load balancer into the newly-created MongoDB VPC. This is the setup I'm going for: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/images/default-vpc-diagram.png but I am trying to use the templates to do this.
What am I doing wrong here? Any help would be much, much appreciated. I have read up a lot about this but still am not sure where to go from here.
Thanks a lot in advance!
Im having this same issue. There seems to be a complete lack of documentation on how to connect an Elastic Beanstalk node.js / express app with the aws Quickstart mongodb cluster set up documentation.
When I run the aws mongo quickstart though it launches a NAT which is public and also a private primary node... maybe this is part of your issue?

MongoDB Amazon Web Service - Do I actually have it installed?

I really want to use mongoDB as my server backend for my android application/ web app that im hosting on the cloud. I ( think ) I installed it on my instance but Im confused as when I run my app its not showing up.
I ssh'd into my EC2 instance ( I am running Elastic Beanstalk on ssh) and I installed mongoDb and created all my tables and when I exit and ssh back into it the same tables are there however after reading up on it, I think the process is a little more complicated than that and more expensive.
Can anyone tell me if what I did was correct and if there actually a way to get mongoDb for free like this on Elastic Beanstalk? Its for my Computer Science masters.
EDIT:
I have now used Cloud Formation and installed mongo DB but now have no idea how to deploy my app without elastic beanstalk as my app runs on apache.
Thank you
No, keypoints to keep in mind:
When you SSH to your Elastic Beanstalk EC2 instances you can see a big message that says that any change that you make directly to your EC2 instances won't be saved anywhere. What I mean, you don't make ANY changes in your EC2s if you are using Elastic Beanstalk.
AWS has a MongoDB on the AWS Cloud: Quick Start Reference Deployment Guide. This document guides you through the process of installing MongoDB (includes a nice CloudFormation template -and it takes only about 15 mins to be ready-)

Connecting Grails app to MongoDB through NAT instance on AWS

I'm currently trying to setup a mongo replica set in a VPC via this quick start guide https://s3.amazonaws.com/quickstart-reference/mongodb/latest/doc/MongoDB_on_the_AWS_Cloud.pdf.
I have a grails app that runs on an AWS instance which used to also host the mongo instance. Now I want to seperate the web app from mongo. I already followed the guide above and have my replica set setup with a NAT instance that I can access via ssh. Now I'm wondering how to configure grails so that it connects to this mongo instance rather than the one on its own instance.
I used to just set the db host and everything in the DataSource.groovy file and everything was fine, but I can't seem to find how to set it up to go through the NAT to the primary replica node.
Do you guys have any idea what I should do next?
Cheers,
Tobias

Elastic Beanstalk Deployment with MongoDB

Would really appreciate some suggestions for resources on how to properly deploy with Elastic Beanstalk with the following stack:
MongoDB
Rails (Puma)
Sidekiq/Redis
Elasticsearch
Do I need to get all these things setup in ebextension files? Or is it a matter of settings things up manually in AWS and then routing them together properly somewhere?
You definitely don't want to run all those on your Elastic Beanstalk servers. Elastic Beanstalk will automatically add or remove servers based on your traffic/server load. You don't want your database to be on one of those servers when it gets deleted.
Elastic Beanstalk is a Platform as a Service that is great for running web servers. There are other services on AWS such as ElastiCache (Redis/Memcached as a service) and Elasticsearch as a service. There are also third parties that provide services that run on AWS such as RedisLabs (Redis as a service) and MongoLab (MongoDB as a service).
You can decide to use any of these services to reduce the amount of system administration work you have to do yourself. Or you can manually setup EC2 Linux servers (outside of Elastic Beanstalk) and install things like Rails and MongoDB and ElasticSearch on them and manage them yourself.
For your case I would recommend something like the following:
Rails: ElasticBeanstalk
MongoDB: MongoLab
Redis: RedisLabs
Elasticsearch: AWS Elasticsearch Service
You would want to setup each of those services and then simply add the connection information for each of them to your Elastic Beanstalk environment so Rails can use them.
Edit:
Here are the best instructions on setting up MongoDB on EC2 manually: https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
For ElastiCache and Elasticsearch, you just click around in the AWS console to provision a Redis server and get the URLs to connect to. Once you have set all these things up, you just need to put the connection parameters in your ElasticBeanstalk environments as custom environment variables, something like:
MONGO_DB_URL="Your MongoDB EC2 internal IP address"
REDIS_URL="the url ElastiCache provided you"
Then read those environment variables in your application when creating connections to those services.
Also, you are going to have to learn about setting up your VPN and security groups to enable everything to connect. For example you will want your Elastic Beanstalk servers in one security group, and MongoDB server(s) in another group. Then you will have to configure the MongoDB security group to allow access from the beanstalk group on the MongoDB port. It's similar for ElastiCache. I think for Elasticsearch you will have to create an IAM role with access to the Elasticsearch API, and then assign that role to your Beanstalk servers.
Of course there is also the administrative tasks of setting up Linux servers for your MongoDB cluster, configuring clustering, fail-over, automated backups, log archives, periodic security updates, etc. I know you have all this AWS credit, but you should weigh moving everything over to AWS versus the cost of all the administrative tasks you will be spending time on. Elastic Beanstalk, Elasticsearch and ElasticCache are a no-brainer if you are getting them for free, but my MongoLab bill would have to be fairly high to justify setting all that up and managing it myself.