How-to: Rotate AWS IAM access keys
Rotate an IAM user's access keys with zero downtime using the two-key overlap.
When to use this
Section titled “When to use this”Security Hub / Trusted Advisor flags a key older than 90 days, or a key may have leaked. (If it leaked: deactivate the old key first, then do this.)
Prereqs: iam:CreateAccessKey, iam:UpdateAccessKey, iam:DeleteAccessKey on the user; know every place the key is used (CI secrets, servers, ~/.aws/credentials).
-
Confirm who you are: AWS: Check which identity you are using
-
List the user’s keys and their age (an IAM user can have at most two):
Terminal window aws iam list-access-keys --user-name <user> -
Create the new key:
Terminal window aws iam create-access-key --user-name <user> -
Update every consumer (CI secret, Vault, servers) with the new key ID + secret.
-
Deactivate (don’t delete yet) the old key:
Terminal window aws iam update-access-key --user-name <user> --access-key-id <old-key-id> --status Inactive -
Wait a day and check nothing broke (
aws iam get-access-key-last-used --access-key-id <old-key-id>should not advance), then delete it:Terminal window aws iam delete-access-key --user-name <user> --access-key-id <old-key-id>
Verify
Section titled “Verify”- Consumers authenticate with the new key (
aws sts get-caller-identityfrom CI). get-access-key-last-usedon the old key stays at the pre-rotation timestamp.
Rollback
Section titled “Rollback”Before step 6: reactivate the old key with --status Active.
References
Section titled “References”- AWS docs: Managing access keys for IAM users
- Better long-term: replace static keys with OIDC roles for CI and SSO for humans.
My DevOps Playbook by Angelo John Calleja