Skip to content

Instantly share code, notes, and snippets.

@coingraham
Created September 12, 2017 17:55
Show Gist options
  • Select an option

  • Save coingraham/e05a6824e0486d225e7035afe01b3b5d to your computer and use it in GitHub Desktop.

Select an option

Save coingraham/e05a6824e0486d225e7035afe01b3b5d to your computer and use it in GitHub Desktop.
Find User by Access Key Python
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