Created
September 12, 2017 17:55
-
-
Save coingraham/e05a6824e0486d225e7035afe01b3b5d to your computer and use it in GitHub Desktop.
Find User by Access Key Python
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
| import boto3 | |
| profile = "my_profile" | |
| region = "us-west-2" | |
| session = boto3.session.Session(profile_name=profile, region_name=region) | |
| iam = session.resource("iam") | |
| def get_user_by_access_key(access_key): | |
| for user in iam.users.all(): | |
| for key in user.access_keys.all(): | |
| if key.id == access_key: | |
| return "Found user {} with key {}".format(user.name, access_key) | |
| return "ERROR: No user found with key {}".format(access_key) | |
| if __name__ == '__main__': | |
| search_key = "AXXXXXXXXXXXXXXXXXXXXXX" | |
| print get_user_by_access_key(search_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment