Created
January 16, 2020 07:51
-
-
Save jcolemorrison/b48635063e6e7942974ccbe0c417bfea to your computer and use it in GitHub Desktop.
EC2 Fundamentals - Automated Node.js Server Launch User Data Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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