Created
August 17, 2016 20:16
-
-
Save artburkart/e71c9f8e3c13007b4feeca697035b2aa to your computer and use it in GitHub Desktop.
Find IAM user with given AWS 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 | |
# Usage: bash find_user_by_aws_access_key.sh SOME_AWS_ACCESS_KEY | |
# This script finds the user in the account who has a given access key | |
ACCESS_KEY=$1 | |
for user in `aws iam list-users | jq -r '.Users[].UserName'`; do | |
USER=`aws iam list-access-keys --user $user | jq '.AccessKeyMetadata[] | select(.AccessKeyId == "'"$ACCESS_KEY"'")'` | |
if [ -n "$USER" ]; then | |
echo "$USER" | |
exit 0 | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment