~cyplo/dotfiles

ref: 1ca69547b9a678da7a89ac93b7822ac478a2ab7d dotfiles/tools/find-iam-user-for-access-key.py -rw-r--r-- 541 bytes
1ca69547 — Cyryl Płotnicki update 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import boto.iam
import sys

iam = boto.connect_iam()

users = iam.get_all_users('/')['list_users_response']['list_users_result']['users']

for user in users:
    for key_result in iam.get_all_access_keys(user['user_name'])['list_access_keys_response']['list_access_keys_result']['access_key_metadata']:
            aws_access_key = key_result['access_key_id']
            for TARGET_ACCESS_KEY in sys.argv[1:]:
                if aws_access_key == TARGET_ACCESS_KEY:
                        print aws_access_key + ' : ' + user['user_name']