Skip to content

Instantly share code, notes, and snippets.

@hiteshchoudhary
Created February 13, 2024 08:59
Show Gist options
  • Save hiteshchoudhary/3a542e1f7294c1b7fe919e98892b4a2c to your computer and use it in GitHub Desktop.
Save hiteshchoudhary/3a542e1f7294c1b7fe919e98892b4a2c to your computer and use it in GitHub Desktop.
Install apache on AWS with metadata
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
EC2AZ=$(TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") \
&& curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "<body style='background-color:#2c3e50; color:#ffffff'><h1>Deployed via AWS</h1><br><h2>Availability Zone: $EC2AZ</h2> </body>" > /var/www/html/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment