Skip to main content
selectAWSlast verified 2026-07-29
Servicesiam
CredentialsAWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
Permissionsiam:ListAccessKeys
Fan-out: account - one call per account. One call per IAM user when swept account-wide

IAM access key age and rotation status

Lists the access keys belonging to one IAM user with each key's age in days. Long-lived keys are the classic credential hygiene finding: compare key_age_days against your rotation window (90 days is the common baseline) and treat Active keys past it as needing rotation. For an account-wide sweep, enumerate users with aws/iam/users-list and iterate this query over them.

Query

SELECT
user_name,
access_key_id,
status,
create_date,
ROUND(julianday('now') - julianday(create_date)) as key_age_days
FROM aws.iam.access_keys
WHERE region = 'us-east-1'
AND UserName = '{{user_name}}';

Notes

UserName is load-bearing: without it the API returns only the calling identity's own keys, which silently looks like a complete answer. IAM is global, so region = 'us-east-1' is endpoint routing. julianday date arithmetic is the default embedded SQLite backend's dialect; on PostgreSQL use EXTRACT(DAY FROM now() - create_date::timestamp). A key that has never been rotated is simply the oldest one for the user - there is no separate last-rotated field, since rotation means creating a new key and deleting the old one. Inactive keys still count as credentials that exist and should be deleted rather than left disabled.

Related queries

  • IAM users enumeration - Enumerates IAM users in the account; IAM is global and always served from us-east-1, so the query takes no parameters.
  • IAM users with console access and no MFA - Lists IAM users alongside whether they have a virtual MFA device registered; console-capable users without MFA are the finding.