Skip to content

Instantly share code, notes, and snippets.

@hongphuc5497
Last active March 24, 2024 17:50
Show Gist options
  • Save hongphuc5497/a7945b3e30b6e70c813ac73e31a2d5b5 to your computer and use it in GitHub Desktop.
Save hongphuc5497/a7945b3e30b6e70c813ac73e31a2d5b5 to your computer and use it in GitHub Desktop.
EC2 User Data script
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
EC2_AZ=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "<h1>Hello World from $(hostname -f) in AZ $EC2_AZ</h1>" > /var/www/html/index.html
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment