Revisions
-
atheiman revised this gist
Aug 4, 2021 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,25 @@ # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html METADATA_TOKEN="$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600')" AVAILABILITY_ZONE="$(curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone)" export AWS_REGION="$(echo "$AVAILABILITY_ZONE" | rev | cut -c 2- | rev)" export AWS_DEFAULT_REGION="$AWS_REGION" export INSTANCE_ID="$(curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/instance-id)" # Instance identity documents is another very useful interface with many key value pairs in json format # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document # { # "accountId" : "111111111111", # "architecture" : "x86_64", # "availabilityZone" : "us-east-1a", # ... # "imageId" : "ami-0123456789", # "instanceType" : "t2.small", # ... # "pendingTime" : "2021-08-04T16:20:26Z", # "privateIp" : "10.0.0.1", # ... # "region" : "us-east-1", # "version" : "2017-09-30" # } -
atheiman revised this gist
Aug 3, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@ METADATA_TOKEN="$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X AVAILABILITY_ZONE="$(curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone)" export AWS_REGION="$(echo "$AVAILABILITY_ZONE" | rev | cut -c 2- | rev)" export AWS_DEFAULT_REGION="$AWS_REGION" export INSTANCE_ID="$(curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/instance-id)" -
atheiman created this gist
Mar 25, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ METADATA_TOKEN="$(curl -s -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600')" AVAILABILITY_ZONE="$(curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone)" export AWS_REGION="$(echo "$AVAILABILITY_ZONE" | rev | cut -c 2- | rev)" export AWS_DEFAULT_REGION="$AWS_REGION" INSTANCE_ID="$(curl -s -H "X-aws-ec2-metadata-token: $METADATA_TOKEN" http://169.254.169.254/latest/meta-data/instance-id)"