Created
April 10, 2023 09:13
-
-
Save piorus/8f3f8773479d2a96b964b2616502bb45 to your computer and use it in GitHub Desktop.
Retrieve basic AWS EC2 Meta Data (Availability Zone, Instance ID, Public IP, Private IP) and put it into HTML file
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 | |
META_DATA_URL="http://169.254.169.254/latest/meta-data" | |
TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` | |
function metadata() { | |
echo `curl -s -H "X-aws-ec2-metadata-token: $TOKEN" "$META_DATA_URL/$1"` | |
} | |
cat <<EOT >> index.html | |
<html> | |
<h1>Bootstrap Demo</h1> | |
<h3>`metadata "/placement/availability-zone"`</h3> | |
<h3>`metadata "/instance-id"`</h3> | |
<h3>`metadata "/public-ipv4"`</h3> | |
<h3>`metadata "/local-ipv4"`</h3> | |
</html> | |
EOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment