Skip to content

Instantly share code, notes, and snippets.

@SimonJinaphant
Last active April 8, 2019 15:14
Show Gist options
  • Save SimonJinaphant/5a90e38e937454f016bf50ee3698e9d9 to your computer and use it in GitHub Desktop.
Save SimonJinaphant/5a90e38e937454f016bf50ee3698e9d9 to your computer and use it in GitHub Desktop.

Setting up SSH

There's a lot of ways of hosting web apps onto AWS EC2, I did it the old-fashion/barebone way where you literally SSH into the EC2 instance and run everything there.

  1. Download the digitalmenu-keypair.pem file off the Credentials folder in our team's Google Drive; this file is your login key into the AWS EC2 instance.
  2. Move the downloaded digitalmenu-keypair.pem file into your SSH folder, typically located in ~/.ssh
  3. To start the SSH connection:
    ssh -i ~/.ssh/digitalmenu-keypair.pem ubuntu@ec2-34-219-160-173.us-west-2.compute.amazonaws.com
    
  4. You should now be login as ubuntu@ip-172-31-17-175

Checking the status of the backend

Once connected you can check to see if there's any running node instance via

ps -A | grep node
  • If the command returns nothing, it means the backend process is not running, you can even verify this if you attempt to open up a browser and goto ec2-34-219-160-173.us-west-2.compute.amazonaws.com:3001/restaurants/1
  • Otherwise you can terminate the current node instance as shown in "Terminating the backend"

Starting the backend

  1. cd into the cpen491/backend folder
  2. Perform npm run start &, note the & which will allow the process to continue running even if you perform a CTRL + C to escape the process and exit the SSH session.
  3. You'll have to perform CTRL + C to escape out of the node process once, but if you perform a ps -A | grep node again you should see a running node instance now.

Do NOT start the cpen491/webclient, it is not configured correctly and will cause the EC2 instance to hang; requiring a forceful restart which will change the IP again (It won't be ec2-34-219-160-173.us-west-2.compute.amazonaws.com anymore)


Terminating the backend

You can get the Process ID (PID) via ps -A | grep node, once you have the PID, you can perform kill <PID> to end the process. Verify that it works by doing ps -A | grep node.

Exiting out of EC2

You can gracefully exit out of the SSH session via the command exit

Getting file onto the EC2 instance

You can upload files via scp

In this example, we're copying a folder name data on our local machine and its content (hence -r for recursive) onto the instance in the same folder name on the EC2 instance.

scp -i ~/.ssh/digitalmenu-keypair.pem -r ~/data ubuntu@ec2-34-219-160-173.us-west-2.compute.amazonaws.com:~/data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment