AWS/Ec2MetaData
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
Get TOKEN env var and then list of endpoints
TOKEN=`curl -sS -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` echo "TOKEN=$TOKEN" curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/
Use TOKEN env to get hostname
# for debug replace -sS with -v curl -H "X-aws-ec2-metadata-token: $TOKEN" -sS http://169.254.169.254/latest/meta-data/local-hostname ; echo curl -H "X-aws-ec2-metadata-token: $TOKEN" -sS http://169.254.169.254/latest/meta-data/public-hostname ; echo
Use TOKEN to get tags (Tags not available by default, have to enable see --metadata-options "InstanceMetadataTags=enabled"
TOKEN=`curl -sS -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` echo "TOKEN=$TOKEN" ## Check for tags curl -H "X-aws-ec2-token: $TOKEN" -sS http://169.254.169.254/latest/meta-data/ | grep "tags" || ( echo "no tags exit=$? in metadata, InstanceMetadataTags not enabled for this instance ?") # curl -H "X-aws-ec2-metadata-token: $TOKEN" -sS http://169.254.169.254/latest/meta-data/tags/instance
Get account number from aws meta-data (search with jq or grep)
TOKEN=`curl -sS -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` echo "TOKEN=$TOKEN" curl -s http://169.254.169.254/latest/dynamic/instance-identity/document ; echo
Online grep for account using linux
curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep -oP '"accountId"\s*:\s*"\K[^"]+'