Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save colebrooke/7c6f2a68063d4ada39fb81956df85dae to your computer and use it in GitHub Desktop.
Save colebrooke/7c6f2a68063d4ada39fb81956df85dae to your computer and use it in GitHub Desktop.
aws find username by access key
# 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