Skip to content

Instantly share code, notes, and snippets.

@shaposhnikoff
Created October 15, 2023 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaposhnikoff/51d0ef64163f4842de450a18befc3638 to your computer and use it in GitHub Desktop.
Save shaposhnikoff/51d0ef64163f4842de450a18befc3638 to your computer and use it in GitHub Desktop.
AWS IAM role last usage date
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