Last active
March 17, 2021 06:02
-
-
Save olen2006/f4d7691968a86931cafcccdc21da829d to your computer and use it in GitHub Desktop.
user data for amazon linux 2 to install node, codedeploy-agent, update packages
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
#!/bin/bash -xe | |
# writing logs into user-data.log instead of cloud-init-output.log during boot | |
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
REGION_ID=`ec2-metadata --availability-zone | awk '{print $2}' | sed 's/.$//'` | |
yum update -y | |
yum install -y ruby | |
curl -O https://aws-codedeploy-${REGION_ID}.s3.${REGION_ID}.amazonaws.com/latest/install | |
chmod +x ./install | |
./install auto | |
rm install | |
# logging current status | |
sudo systemctl status codedeploy-agent | |
systemctl is-enabled codedeploy-agent | |
cd /home/ec2-user | |
yum install -y gcc-c++ make | |
curl -sL https://rpm.nodesource.com/setup_15.x | sudo -E bash - | |
yum install -y nodejs | |
cat << EOF > /etc/systemd/system/unit-file.service | |
[Unit] | |
Description= service that consumes data | |
[Service] | |
Type=simple | |
User=ec2-user | |
Group=ec2-user | |
ExecStart=/usr/bin/node index.js tcps://<link>:<port> <login> <pass> | |
Restart=no | |
WorkingDirectory=/home/ec2-user/project-dir/ | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
# S3 | |
aws s3 sync s3://bucket/project-dir/ project-dir | |
chown -R ec2-user:ec2-user project-dir | |
cd project-dir | |
mkdir logs | |
cat << EOF > .env | |
AIRPORT_CONFIG_BUCKET_NAME= | |
AIRPORT_CONFIG_FILE_NAME= | |
SWIM_FEED_URL= | |
SWIM_USERNAME= | |
SWIM_PASSWORD= | |
SFDPS_QUEUE_URL= | |
TFMS_QUEUE_URL= | |
EOF | |
npm i -g && npm update | |
systemctl daemon-reload | |
systemctl enable unit-file | |
systemctl start unit-file | |
systemctl status unit-file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment