Created
June 29, 2021 14:53
-
-
Save wignesh/e648893b958adf69e36c9e8932327d0f to your computer and use it in GitHub Desktop.
EC2 user data to install apache web server on Amazon Linux 2 Image
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
| #!/bin/bash | |
| yum update -y | |
| yum install -y httpd | |
| instanceId=$(curl http://169.254.169.254/latest/meta-data/instance-id) | |
| localIpv4=$(curl http://169.254.169.254/latest/meta-data/local-ipv4) | |
| localHostname=$(curl http://169.254.169.254/latest/meta-data/local-hostname) | |
| publicHostname=$(curl http://169.254.169.254/latest/meta-data/public-hostname) | |
| publicIpv4=$(curl http://169.254.169.254/latest/meta-data/public-ipv4) | |
| securityGroups=$(curl http://169.254.169.254/latest/meta-data/security-groups) | |
| echo "<h1>Hello World from $instanceId</h1><h1>Local IPV4 : $localIpv4</h1><h1>Local Hostname : $localHostname</h1><h1>Public IPV4 : $publicIpv4</h1><h1>Public Hostname : $publicHostname</h1><h1>Security Groups : $securityGroups</h1>" > /var/www/html/index.html | |
| systemctl start httpd | |
| systemctl enable httpd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment