Deploy NodeJS App to AWS EC2!
Deploy NodeJS App to AWS EC2.
- Create EC2 Instance
- find EC2

- Filter “Free Tier Only”, Select “Ubuntu”

- Select “t2.micro (free tier)”

- launch instance

- find EC2
- Generate a Key file and download it
- generate and download the key

- generate and download the key
- SSH into the EC2 instance with your key file
- open terminal

- cd into the directory that has the key you downloaded. for example, if you save the key in Desktop:
cd ~/Desktop - Find instructions on how to connect to EC2 via SSH. In terminal, type the command that change the key access mod, and SSH into EC2

- open terminal
- Clone down the app into EC2
- git clone down the repo that has your app. For example, I have an app:
sudo git clone https://github.com/7seven7lst/demo-ec2-nodejs.git - alternatively, you can also scp a directory into the ec2 instance (if you are using ubuntu instance):
scp -i <your_PEM_key> -r <your_project_folder>/* ubuntu@e<ec2_public_dns>:/home/ubuntu
- git clone down the repo that has your app. For example, I have an app:
- Install relavent packages needed to run app.
-
Note, if you are not using Ubuntu, but some other linux server, you may have “yum” as package manager, instead of “apt-get”. In this case, type “sudo yum update”, etc….
-
sudo apt-get update -
sudo apt-get upgrade -
sudo apt-get install nodejs-legacy -
sudo apt-get install npm
-
- Deploy App
- cd into the app directory
cd demo-ec2-nodejs # this is the name of my app -
npm install -
node index.js
- cd into the app directory
- Expose the port
- find security group option

- choose the security group (should have something “wizard”)

- Expose app port to outside

- find security group option
- Navigate to the url
- copy the url

- In brower addres bar, type
<url>:3001and see the result
- copy the url
- Navigating to observe dashboard chart and coudwatch
- dashboard

- cloudwatch monitoring

- dashboard
- Don’t forget to shutdown the EC2 instance
- Stop the instance

- Terminate the instance
- Stop the instance
Written on September 8, 2018