Skip to content

Instantly share code, notes, and snippets.

@jheerman
Last active November 2, 2023 20:30
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 jheerman/1a15a0a504a35eb99018d750c3f45c40 to your computer and use it in GitHub Desktop.
Save jheerman/1a15a0a504a35eb99018d750c3f45c40 to your computer and use it in GitHub Desktop.
Get AWS roles where last usage is greater than specified date
aws iam list-roles | jq -r '.Roles[].RoleName' | xargs -I % aws iam get-role --role-name % | jq --arg cutoff '2023-04-01T00:00' '.[] | select(.RoleLastUsed.LastUsedDate | . <= $cutoff ) | {RoleName: .RoleName, LastUsedDate: .RoleLastUsed.LastUsedDate}' | jq -s '.' > roles_last_used_april.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment