Deploying Node, Mongo to AWS EC2

Adrienne Tran
Aug 29, 2017 · 1 min read

This guide assumes you have already set up the environment and downloaded the .pem file. Make sure you put the .pem key somewhere safe.

Connect to environment

Click on your instance and hitting “Connect” — you’ll see a URL like this. Copy and paste it into terminal:

ssh -i “<LOCATION OF PEM KEY>” ubuntu@<amazon aws url>

Install Mongo on your VM

The documentation is on point: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Install Node on your VM

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Installing Node installs NPM.

Install Express on your VM

sudo npm install -g express

Change IP tables on your VM

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080  
sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -o lo -j REDIRECT --to-ports 8080

See this guide for reference.

Edit your security groups on AWS

Clone your git repo

In /home/ubuntu:

git clone https://github.com/<YOURUSERNAME>/<YOURREPO>.git
npm install

Start your server

node server.js

Visit your new page

Get your public DNS from your Amazon console page.

<amazon public DNS here>:8080

e.g. http://ec2-44-146-1-324.us-east-1.compute.amazonaws.com:8080/

)
Adrienne Tran

Written by

Product @ Tesla. Ex-Google, Ex-Bridgewater.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade