Forked from caueops/aws-iam-get-username-by-access-key.bash
Created
July 3, 2019 11:11
-
-
Save danielnbalasoiu/bbbe7454a8a8a4b193c2144e80369e4c to your computer and use it in GitHub Desktop.
AWS IAM Get UserName by Access Key Id
This file contains hidden or 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