Differences between revisions 2 and 3
Revision 2 as of 2022-05-01 21:37:48
Size: 1170
Editor: PieterSmit
Comment:
Revision 3 as of 2022-05-01 21:41:48
Size: 1381
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 20: Line 20:
## 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 ?")
#

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

AWS/Ec2MetaData (last edited 2022-05-01 21:59:56 by PieterSmit)