Skip to content

Instantly share code, notes, and snippets.

@nonrational
Last active June 3, 2021 13:23
Show Gist options
  • Save nonrational/def2d71622d25e4433a6 to your computer and use it in GitHub Desktop.
Save nonrational/def2d71622d25e4433a6 to your computer and use it in GitHub Desktop.
list IAM keys / identities (awscli, underscore-cli or jq)
for u in $(aws iam list-users | jq ".Users[].UserName" --raw-output); do
aws iam list-access-keys --user $u | jq '.AccessKeyMetadata[] | .UserName + ":" + .AccessKeyId' ;
done
# list iam keys by user in an easily grepable format.
# easily find which identity matches a particular iam key
# requires underscore-cli
names=$(aws iam list-users | underscore flatten | underscore pluck "UserName" | tr -d '[],"')
for name in $names; do
keys=$(aws iam list-access-keys | underscore flatten | underscore pluck "AccessKeyId" | tr -d '[],"')
for key in $keys; do
echo "$name : $key"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment