Using MongoDB with AWS ElasticBean application - node.js

I have an ElasticBean application running (setup with NodeJS) and I wondered what the best way to integrate MongoDB would be. As of now, all I've done is ssh into my eb instance (with the eb cli) and install mongodb. My main worry comes from the fact that the mongo db exists in my instance. As I understand it, that means that my data will most certainly be lost as soon as I terminate my instance. Is that correct? If so the what is the best way to go about hooking en EB app to a MongoDB? Does AWS support that natively without having to go rent a DB on a dedicated server?

You definitely do NOT want to install MongoDB on an Elastic Beanstalk instance.
You have a few options for running MongoDB on AWS. You can install it yourself on some EC2 servers (NOT Elastic Beanstalk servers) and handle all the management of that yourself. The other option is to use mLab (previously MongoLab) which is a managed MongoDB as a Service provider that works on AWS as well as other cloud services. Using mLab you can easily provision a MongoDB database in the same AWS region as your Elastic Beanstalk servers.
Given the steps involved in setting up a highly-available MongoDB cluster on AWS I generally recommend using mLab instead of trying to handle it yourself. Just know that the free-tier is not very performant and you will want to upgrade to one of the paid plans for your production database.

Been there, done that. As #MarkB suggested it´d be a lot easier to use a SaaS instead.
AWS by itself doesn´t have a native MongoDB support but deppending of your requierements you could find a solution with little or no extra cost (beside EC2 price) on Amazon Marketplace. These images are vendor´s pre-configured production-ready AMIs of popular tools like MongoDB.

Related

Mongo db replication using node js

I am new to MongoDB and NodeJS. I am running an ec2 instance on AWS and I want to sync the data of AWS to local systems and local to AWS. I don't have any idea about how to do it. I have tried some configuration in database files but I am not able to connect my local system with remote server.
I found this repository on git hub https://github.com/sheharyarn/mongo-sync but I don't know how to use that repository in my code.
Kindly help me.
Thank you
Mongodb atlas provides free 512MB of space. You can create cluster in mongoldb atlas and use online database from anywhere. it will work on your local machine and also on aws server.
Just open mongoldb website you can find mongoldb atlas easily. after sign up.

Deploy React, Node/Express, and MySQL web application onto the web with Amazon AWS

I have lately been learning React and Node js and have been having a lot of fun. I am wanting to deploy / publish my work onto the internet using Amazon AWS (to share my app with friends and potential employers). However, I am having trouble.
I have researched this process quite a bit and can't seem to find any resources that are detailed enough and that touch each aspect of my web app. To clarify, my front end is written in React and my back end is in Node/Express js, and that is connected to a MySQL database. Currently all of this is stored locally on my computer.
I'm not sure how to proceed...I've played around with adding all my code to github and running through the deploy feature on AWS Amplify, but that seemed limited to the react front end (at least I could not discover anything about including the functionality of my back end and including my database connection AND queries from Node).
Can anyone point me in the right direction? Providing any tips, suggestions, and/or resources to aid in this process would be appreciated. Specifically to this question: How to I deploy my React, Node/Express, and MySQL web app (currently stored completely on my local computer) to the internet through Amazon AWS?
To generify the question a little: you want to deploy a frontend, a backend and a database to AWS.
(Un)fortunately, there are lots of different options for this. Let's explore a little.
Frontend
Assuming that your frontend is a set of static resources (html/js/css), you don't need much more than a web server. You can use either S3 (an object store that can also serve web sites), or Cloudfront (a content delivery network), or run a virtual machine on EC2, install a web server there and deploy your frontend there.
Backend
Lots of options here. You can package your app in a Docker container and use ECS (container service or EKS (kubernetes service). You could also run your backend on Elastic beanstalk (comparable to Heroku). Or, run a virtual machine on EC2 and deploy your backend there.
Database
You can choose between a managed/hosted database like RDS, or roll your own by installing it on a virtual machine and installing a database server there.
So, what to pick? It depends on what you're comfortable with. If you have a bit experience with managing Linux servers, you could start an EC2 instance, install a web server like nginx or apache, install NodeJS, install MySQL and then copy your frontend, backend and database scripts/backup to the server.
If you're not comfortable with managing Linux servers, you could go for hosted/managed solutions like S3, Elastic beanstalk and RDS.
Do that, that when your frontend is running on a different domain/url than your backend, your backend needs to set CORS headers otherwise the browser won't allow your frontend to make HTTP requests to your backend.
Hope this helps - good luck!
Elastic Beanstalk (EB) could be a good start, as it can provision all resources that are needed for node.js applications, without much knowledge required about setting up and managing everything from scratch:
Deploying Node.js applications to Elastic Beanstalk.
For simplicity you can start with single instance environment type (no load balancer) and see how it goes.
EB can also setup a database for you:
Adding a database to your Elastic Beanstalk environment
If you get more comfortable about working with AWS, you can scale up into load balanced EB environment, or look at other options, such as your own EC2 instances with autoscaling groups, load balancers, container services and more.

Using same EC2 instance for node and mongo hosting

Can I use my aws EC2 instance to run both node server and mongo server by installing mongo driver into my EC2 instance ?
Its gotta be just like how we do it in our localhost, right?
I'd rather advise you to separate concerns and have dedicated instances for nodejs and for mongodb. It's not only good practice to separate app and db but also you'll able to scale much easier, and you'll scale exactly what you need.

Deploy node.js in production

What are the best practices for deploying a nodejs application in production?
I would like to know how deploy for production Api's nodejs is being done today, today my application is in docker and running locally.
I wonder if I should use a Nginx inside the container and deploy my server on it or just upload my image node that is already running today.
*I need load balance
There are few main types of deployment that are popular today.
Using platform as a service like Heroku
Using a VPS like AWS, Digital Ocean etc.
Using a dedicated server
This list is in the order of growing difficulty and control. So it's easiest with PaaS but you get more control with a dedicated server - thought it gets significantly more difficult, especially when you need to scale out and build clusters.
See this answer for more details on how to install Node on a VPS or a dedicated server:
how to run node js on dedicated server?
I can only add from experience on AWS using a NAT Gateway which is a dedicated Node server with a MongoDB server behind the gateway. (Obviously this is a scalable system and project.)
With or without Docker, you need to control the production environment. This means clearly defining which NPM libraries you will need for production, how you handle environment variables and clusters for cores.
I would suggest, very strongly, using a tool like PM2 to handle clusters, server shutdowns and restarts and logs. (Workers & slaves also if you need them and code for them).
This list can go on and on, but keep in mind this is only from an AWS perspective. Setting up a Gateway correctly on AWS is also not an easy process. Be prepared for some gotcha's along the way.

nodejs, docker, nginx and amazon aws deployment

There have been many questions regarding docker, node and amazon aws and I have read most of them but I haven't got my answer.
I have been working on a production node.js API project for last some weeks and now that the API's are complete I have to deploy them.
There are a total of 2 microservices (this may increase later) and some worker processes. Different components of the system will communicate with each other using SQS and SNS. Each of the microservices uses mongo DB as the nosql storage and mongoose as the ODM. I chose mongolab as the mongoDB hosting provider. Currently I can connect to mongolab DB using MONGOLAB_URI environment variable (obviously this will not be enough during production any suggestion on this one is welcome)
I am going ahead with amazon aws platform.
My thought process is:
I will docerize each of the components. For worker processes it is straight forward.
For microservices I will have 2 docker images which I will deploy using amazon EC2 container service. I will have a third nginx docker image which I will put in front of node applications.
I am planning to create a cluster of 2 machines (c2 large) initially and host these 3 dockerized microservices and nginx images on these machines.
Obviously the node process will run on some port. Lets assume it to be 3100
Till now it is perfectly clear the problem came when I want to exposes these API's to outer world
The microservices exposes some endpoints like
service 1:- /users, /login, /me etc
service 2: /offers, /gifts etc
My Question is:
I want to resolve
mydomain.com/api/v1/users to service1:3100/users
similarly for other API's
I assume this can be done by nginx but I am not much familiar with it.
The constraints are:
I don't want to host each of the microservice on a separate machine (budget constraint).
I don't know which service will run on which machine (this I assume since I read that ec2 container service will automatically start docker processes on random machines and distribute load).
How Can I do this ?

Resources