-
-
Save Laxman-SM/5bfe5910c5a3d761d739e8c627a7ffab to your computer and use it in GitHub Desktop.
aws find username by access key
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
# example: python find_username_by_access_key.py <your_key> | |
import sys, boto3 | |
TARGET_ACCESS_KEY = sys.argv[1] | |
client = boto3.client('iam') | |
paginator = client.get_paginator('list_users') | |
response_iterator = paginator.paginate( | |
PaginationConfig={ | |
'MaxItems': 150, | |
'PageSize': 150}) | |
for page in response_iterator: | |
u = page['Users'] | |
for user in u: | |
for key_result in client.list_access_keys(UserName = user['UserName'])['AccessKeyMetadata']: | |
aws_access_key = key_result['AccessKeyId'] | |
if aws_access_key == TARGET_ACCESS_KEY: | |
print 'User: ' + user['UserName'] | |
print 'Key: ' + aws_access_key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment