Created
October 15, 2023 08:34
-
-
Save shaposhnikoff/51d0ef64163f4842de450a18befc3638 to your computer and use it in GitHub Desktop.
AWS IAM role last usage date
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
import boto3 | |
client = boto3.client('iam') | |
paginator = client.get_paginator('list_roles') | |
for page in paginator.paginate(): | |
for listed_role in page['Roles']: | |
role_name = listed_role['RoleName'] | |
role = client.get_role(RoleName=role_name)['Role'] | |
last_used = role.get('RoleLastUsed', {}).get('LastUsedDate') | |
print(f"{role_name}: {last_used}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment