Retrieve AWS AccountID from metadata
There has not been a way to discover the AWS Account ID for some time from within the command line in Linux, but now there is and it took me some digging to find it. You will find everything for your specific instance from the AWS Account ID, to the region, availability zone, AMI, etc. The code is shown below.
1 2 3 |
awsAccountID=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep 'accountId' | awk -F'"' '{print $4}') |