Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 2.32 KB

node-ec2.md

File metadata and controls

40 lines (35 loc) · 2.32 KB

Spin up AWS EC2 configured Node App

Note that the IP address 111.222.333.444 needs replaced with whatever IP you generate as your elastic IP.

Work in Progress, brain dump from @scarstens

  1. Create VPC (if not already exists)
  2. Create security group with "my ip" access to all ports.
  3. Create security group for "http_https_open" and open 80 and 443 to the public
  4. Create IAM role for "default_ec2_role", assign it basic S3 read access for now.
  5. Create EC2 -> Select free teir Ubuntu 16 AMI
  6. assign it to the VPC, Security Groups, and IAM role created above
  7. default tags, storage space, and other options all fine as default
  8. use wizard to create PEM keypair (or select existing keypair) -> download the PEM -> move it to ~/.ssh -> chmod 600 the PEM key
  9. finalize / spin up instance
  10. create elastic ip -> assign it to the instance
  11. ssh into the ec2 instance with something like ssh ubuntu@111.222.333.444 -i ~/.ssh/KEYNAME.pem
  12. git clone https://github.com/scarstens/devops-toolkit
  13. bash devops-toolkit/setup-git-credentials.sh
  14. if you haven't already, get your github handle (username)
  15. if you haven't already, generate and prepare your github personal access token https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
  16. enter these two items into the prompts (note you won't see anything when it asks for password, this is a security feature)
  17. bash devops-toolkit/beta/node-express.sh
  18. curl localhost (should display hello world)
  19. create github repo with actual node app (private or public at this point)
  20. stop the current node app pm2 stop nodeapp
  21. remove (backup) the sample node app sudo mv /var/www/nodeapp /var/www/default_nodeapp
  22. clone your new repo onto the previous nodeapp folder location git clone https://github.com/myuser/myrepo /var/www/nodeapp
  23. rebuild the node app based on its package.js cd /var/www/nodeapp ; npm install --save
  24. restart the node app runner pm2 start nodeapp

Now you can update the node app automatically by stopping, git pulling, and starting the node app. Would look something like this:

cd ~/devops-toolkit ; git pull ; bash update-pm2-nodeapp.sh ;'

Or you can run it remotely using a command similar to this:

ssh ubuntu@111.222.333.444 'cd ~/devops-toolkit ; git pull ; bash update-pm2-nodeapp.sh ;'`