Skip to content

Instantly share code, notes, and snippets.

@mohankumar-i2i
Last active August 6, 2020 02:05
Show Gist options
  • Save mohankumar-i2i/cb9db42c255dfa8d882c143741a8bce4 to your computer and use it in GitHub Desktop.
Save mohankumar-i2i/cb9db42c255dfa8d882c143741a8bce4 to your computer and use it in GitHub Desktop.
Sample user data for ec2
#!/bin/bash
# install httpd (Linux 2 version)
# create role with s3 write access privilege and set to ec2 instance
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
usermod -a -G apache ec2-user
chown -R ec2-user:apache /var/www/html
chmod 2775 /var/www/html
find /var/www/html -type d -exec chmod 2775 {} \;
find /var/www/html -type f -exec chmod 0664 {} \;
echo "<h1 style='color: #5e9ca0;'>instance-id:: <span style='color: #2b2301;'>$(hostname -f)</span>!</h1>" > /var/www/html/index.html
echo "<h1 style='color: #ff1605;'>instance-id:: <span style='color: #4800ff;'>$(hostname -f)</span>!</h1>" > /var/www/html/welcome.html
aws s3 mb s3://bucketName --region us-east-1
aws s3 cp /var/www/html/index.html s3://bucketName
aws s3 cp /var/www/html/welcome.html s3://bucketName
# curl http://169.254.169.254/latest/meta-data/instance-id
# to debug user-data
# cat /var/log/cloud-init-output.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment