Skip to content

Instantly share code, notes, and snippets.

@jcolemorrison
Created January 16, 2020 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcolemorrison/b48635063e6e7942974ccbe0c417bfea to your computer and use it in GitHub Desktop.
Save jcolemorrison/b48635063e6e7942974ccbe0c417bfea to your computer and use it in GitHub Desktop.
EC2 Fundamentals - Automated Node.js Server Launch User Data Script
#!/usr/bin/env bash
# Install Node and Git
yum update -y
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs git
# Make a directory to clone the application code to
mkdir -p /home/ec2-user/app && cd /home/ec2-user/app
git clone https://github.com/jcolemorrison/ec2-lb-api.git .
# Install Dependencies
npm install
# Redirect Port 3000 to Port 80 Traffic
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
# Start the server
node . > stdout.log 2> stderr.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment