Created
January 5, 2019 18:10
-
-
Save cauealvesbraz/1121c0a0375648db13b137b31ef8955d to your computer and use it in GitHub Desktop.
AWS IAM Get UserName by Access Key Id
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 characters
#!/bin/bash | |
# exit when the command fails | |
set -o errexit; | |
# exit when try to use undeclared var | |
set -o nounset; | |
accessKeyToSearch=${1?"Usage: bash $0 AccessKeyId"} | |
for username in $(aws iam list-users --query 'Users[*].UserName' --output text); do | |
for accessKeyId in $(aws iam list-access-keys --user-name $username --query 'AccessKeyMetadata[*].AccessKeyId' --output text); do | |
if [ "$accessKeyToSearch" = "$accessKeyId" ]; then | |
echo $username; | |
break; | |
fi; | |
done; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment