Jimbojones1 / ec2postgres-walkthrough

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Intro to AWS

Set Up

setup.mp4

AWS Console

  1. Sign In
  2. Search EC2
  3. Hover ove EC2
  4. Click Dashboard
  5. Launch instance: Click Launch Instance
  6. Name and tags: Give it a name
  7. Application and OS Images (Amazon Machine Image): Choose Ubuntu
  8. Key pair (login): Create new key pair
  9. Key pair name: give it a name
  10. Key pair type: ED25519
  11. Click Create key pair
  12. Download file
  13. Advanced Details: paste user data file
  14. Click launch instance

User data Script

#!/bin/bash
sudo apt-get -y update
sudo apt-get -y install postgresql
sudo -u postgres psql -d postgres -c "CREATE USER ubuntu SUPERUSER LOGIN PASSWORD 'ubuntu'";
echo "export PGPASSWORD=ubuntu" >> /home/ubuntu/.profile
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - 
sudo apt install nodejs

Connect

connecting.mov
  1. After creation, wait a few minutes for the installation of the tools to complete and click on Connect to instance

  2. From EC2 Dashboard:

    1. Resources: click Instances (running)
    2. Click Instance ID
    3. Click Connect
  3. Click SSH Client of not already chosen

  4. Locally, locate directory containing .pem file

  5. chmod 400 pern.cer (substitute filename for pern.cer)

  6. copy Example connect command from AWS page

  7. confirm connecting

GitHub

github.mp4
  1. clone repo via https
  2. cd into repo
  3. npm i
  4. start tmux session
  5. node server.js

Tmux

  1. tmux new -s mernapp to start session
  2. ctrl+b d to detach
  3. tmux ls list sessions
  4. tmux attach-session -t mernapp reattach session
  5. tmux kill-session -t mernapp destroy session
    • (ctrl+c to stop process and then exit from within tmux is preferable)

AWS Console

aws_console.mov
  1. Go to EC2 Dashboard
  2. Resources: Click on Instances (running)
  3. Click on Instance ID
  4. Click on Security Tab
  5. Click on link under Security Groups
  6. Click on Edit inbound rules
  7. Click on Add Rule
  8. Choose Custom TCP
  9. For Port range enter 3000 or whatever
    • each time a new app is deployed, a new unique port number must be opened and the app must listen on it
  10. For Source choose Anywhere-IPv4
  11. Click Save rules
  12. Click on Instances
  13. Click on Insance ID
  14. Copy Public IPv4 address or Public IPv4 DNS
  15. Paste into browser and add :3000 after it

Assign Elastic IP

elastic_ips.mov
  1. In EC2 Dashboard, click on Elastic IPs in left menu bar
  2. Click "Allocate Elastic IP address"
  3. Click "Allocate"
  4. Click on "Actions" dropdown
  5. Choose "Associate Elastic IP address"
  6. Click into "Instance" text input
  7. Choose your instance from autocomplete option
  8. Click on "Associate"
  9. Click on "Instances" in left menu bar
  10. Click on instance id
  11. Note existence of "Elastic IP Address"
  12. Use this IP address instead of previous IP address.

Monitoring the app for downtime

AWS sporadically restarts EC2 instances with no warning. The simplest solution is to use https://www.downnotifier.com/

  1. Enter Website URL
  2. Enter your email address
  3. Make sure "Notify Me: When the site is offline" is selected
  4. Click "Start monitoring my website"

About


Languages

Language:JavaScript 100.0%