Chris Mendez in NodeJS, Javascript, For Developers, APIs, SaaS, IaaS, PaaS, AWS

AWS: Install a Node app on AWS

I normally use Heroku or Openshift to publish apps but AWS works too. Here's a cheatsheet on how to set-up your NodeJS server from scratch on AWS.

This cheatsheet will focus on the development environment and not dive into making a node app.


Create an EC2 Server

Step 1 - Create a PEM

You need to create an PEM key in order to gain access to your AWS server.

Step 2 - Launch EC2

You need to Launch an Instance of EC2 using the EC2 Console.

https://console.aws.amazon.com/ec2/

This is where you will pick the PEM you just created.

Step 3 - Create A-Record

It's recommended that you create a static IP address to your EC2, then assign an domain A-Record to your static IP address.

https://pragmaticintegrator.wordpress.com/2012/12/13/assign-a-fixed-ip-to-aws-ec2-instance/

Step 4 - SSH

You can SSH into your new EC2 instance using PEM.

ssh -i ~/Desktop/keys.pem ec2-user@domainname.com  

Step 5 - Configure Root

Once you've used SSH to log into the server, you then should configure your server by first creating a root password.

keys = {root: p@ssword }  
sudo passwd root  

Install NodeJS

Step 6 - Install packages

Become a root user

su root  

YUM is your package manager and it's advised that you update it before you begin.

sudo yum update  

Install GCC

sudo yum install gcc-c++ make  

Install OpenSSL

sudo yum install openssl-devel  

Install git so that you can checkout node.

sudo yum install git  

Change director to /usr/src

 cd /usr/src

Download NodeJS

sudo git clone git@github.com:nodejs/node.git  

Change directory into /node

cd node  

Step 7 - Check out Node

Checkout the version of node you need. If you need something that's stable, it might help to review this page

git checkout v4.6.0  
./configure
make  
sudo make install  

Step 8 - Configure Node

Configure NodeJS

sudo nano /etc/sudoers  

Step 9

Configure environmental variables by making this line:

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin  

Look like this:

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin  

Step 10 - Install npm

Install Node Package Manager (NPM)

sudo yum install curl  
sudo su  
PATH=$PATH:/home/ec2-user/node  
export PATH  
curl https://npmjs.org/install.sh | sh  
exit  

Step 11 - Install a few more packages

Install ExpressJS and Forever packages from npm.

 sudo npm install express -g
 sudo npm install forever -g

Your done!


Resources