Created
January 16, 2020 07:54
-
-
Save jcolemorrison/ca732e73629726bad92adf0943a7546c to your computer and use it in GitHub Desktop.
EC2 Fundamentals - Automated Node.js Server Launch Custom User Data Script and Examples
This file contains hidden or 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
# If your given node application has a different start command, replace the line in the script... | |
# rest of the userdata.sh script above.... | |
# Start the server | |
node . > stdout.log 2> stderr.log | |
# with... | |
# rest of the userdata.sh script above.... | |
# Start the server | |
yourcommand > stdout.log 2> stderr.log | |
### FULL EXAMPLE BELOW | |
### IF YOU USE THE BELOW, DO NOT INCLUDE ANYTHING FROM LINE 12 and ABOVE!! | |
#!/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 | |
npm start > stdout.log 2> stderr.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment