Skip to content

Instantly share code, notes, and snippets.

@bashtoni
Created December 11, 2017 13:32
Show Gist options
  • Save bashtoni/7804fef232288f2962b435ae056a54e0 to your computer and use it in GitHub Desktop.
Save bashtoni/7804fef232288f2962b435ae056a54e0 to your computer and use it in GitHub Desktop.
Find when AWS access keys were last used
#!/bin/bash
for user in $(aws iam list-users --query 'Users[].UserName' --output text); do
for key in $(aws iam list-access-keys --user-name $user --query 'AccessKeyMetadata[].AccessKeyId' --output text); do
aws iam get-access-key-last-used --access-key-id $key --query '[UserName,AccessKeyLastUsed.LastUsedDate]' --output text
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment