20210626112245-aws-deployment

from Eric Pearson (@nyloneric): https://gist.github.com/NylonEric/372516f2fe3c9f708d20e7e2f77007cb#file-2021-06-23-md

June 23, 2021

Overview

Deploy all the things! http://frontendcapstone.com

Log

10:00om - 2:00am

Challenge/Motivation

Get repo onto AWS instance and connect through a persistant IP or domain name

Actions Taken

deploy! set up domain frontendcapstone.com w/ google domains (domains.google.com)

AWS

https://aws.amazon.com/ec2/getting-started/

set up security policy on AWS EC2 I started with everything open and then restricted to port 80 UDP/TCP traffic for incomming. I also openned ICMP traffic for pinging purposes as well as ssh port 22 for logging into server.

set up elastic IP so it will persist after reboot/termination

Linux/UNIX instance:

Logging in:

ssh from local: set permissions to pem file: chmod 400 hr-nylon-eric.pem

ssh -i hr-nylon-eric.pem ec2-user@ec2-35-172-51-196.compute-1.amazonaws.com

Then navigate to and create folder for project:

git clone https://github.com/Idakka/Project-Atelier.git
sudo yum install git

Setting up Node:

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
nvm install node
. ~/.nvm/nvm.sh
node -e "console.log('Running Node.js ' + process.version)"
npm install -g npx

router/ reverse proxy:

sudo amazon-linux-extras install nginx1
sudo service nginx start
cat /etc/nginx/sites-available/default
 server { listen 80; server_name tutorial; location / {  proxy_set_header  X-Real-IP  $remote_addr; proxy_set_header  Host        $http_host; proxy_pass        http://127.0.0.1:3000; } }

link config files

sudo service nginx restart

install webpack

npm install webpack
npm start

keep it running:

https://medium.com/hackernoon/tutorial-creating-and-managing-a-node-js-server-on-aws-part-2-5fbdea95f8a1#.mnlkymeti

npm i -g pm2
pm2 start tutorial/index.js

save config with everything running (no nginx at this point) pm2 save

pm2 start nodemon server/server.js

That’s it! You can log out/in to SSH, even restart your server and it will continue to run on port 80.

nginx persistent:

systemctl start nginx
systemctl enable nginx

having trouble restarting nginx on reboot, sudo systemctl enable nginx

Results Observed

I got the app deployed pretty quickly but had to troubleshoot making the node server and nginx reverse-proxy persist after reboot.

Last modified: 202108151939