← All articles

AWS Secrets Manager rotate IAM access keys: full setup

A closed teal box, two blank cards and an open notebook on a pale desk.
Keep credential storage, replacement planning and verification records distinct.

Key takeaways

  • Secrets Manager rotates IAM access keys via a managed Lambda that creates a second key, stages it AWSCURRENT, and deletes the old key on the next cycle.
  • The secret must be a flat JSON blob containing the username and access key fields, one secret per IAM user.
  • IAM's two-active-keys-per-user limit is what enables zero-downtime staged rotation.
  • Applications only pick up the new key if they re-fetch the secret; anything cached at boot keeps the old key until restart.
  • Most rotation failures trace to missing execution role permissions, the two-key limit, or a too-short Lambda timeout.

AWS Secrets Manager can rotate IAM access keys through a managed Lambda rotation function that creates a second key, updates the secret, stages it as AWSCURRENT, retires the old key as AWSPREVIOUS, and deletes it on the next cycle. This walkthrough covers the exact secret JSON structure, required metadata fields, scheduling options, and the failure states you will hit along the way.

What does AWS Secrets Manager actually rotate for IAM access keys?

Secrets Manager ships a managed rotation Lambda template for IAM user access keys. It creates a new key, updates the secret, waits for a staging label you set, then deactivates and removes the old key. The secret value never leaves the vault; the function talks to IAM directly.

The four-key staging model

The template tracks four labels: AWSCURRENT, AWSPREVIOUS, AWSPENDING, and AWSPENDINGDELETE. On rotation, a new key becomes AWSPENDING, then AWSCURRENT after your test step, while the prior key shifts to AWSPREVIOUS and is deleted on the next cycle. The exact field names and label behavior are documented in the AWS Secrets Manager rotation docs.

What it does not rotate

It only covers IAM user access keys in AWS. Stripe keys, GitHub tokens, and other SaaS credentials stay outside, and nothing tracks who owns each secret or when the next deadline lands. That gap is what manual credential rotation tracking tries to fill.

How do you set up the rotation Lambda for an IAM access key secret?

Secrets Manager ships a managed rotation template for IAM access keys. It creates a new key, updates the secret, waits for you to confirm, then deactivates the old one. You attach it to an existing secret and pick a schedule.

Enable rotation in the console

Open the secret in the Secrets Manager console, choose Edit rotation, then Enable automatic rotation. Select the AWS IAM access key template, pick a rotation schedule (30, 60, or 90 days matches most rotation policies), and choose or create a Lambda function. Secrets Manager offers to create the function for you, which generates the execution role at the same time. The first rotation runs immediately unless you change that setting.

Enable rotation with the CLI

aws secretsmanager rotate-secret \
  --secret-id prod/payments-platform/iam-key \
  --rotation-lambda-arn arn:aws:lambda:us-east-1:123456789012:function:SecretsManagerIAMKeyRotation \
  --rotation-rules "{\"AutomaticallyAfterDays\": 60}"

The function must live in the same region as the secret. Verify with aws secretsmanager describe-secret --secret-id <name> and check RotationRules and LastRotatedDate in the response.

Least-privilege execution role

The Lambda execution role needs iam:CreateAccessKey, iam:UpdateAccessKey, and iam:DeleteAccessKey scoped to the target IAM user, plus secretsmanager:DescribeSecret and secretsmanager:PutSecretValue scoped to the secret itself. Resist the temptation to grant iam:* on the account: the function only touches one user's keys, and the audit trail should show exactly that. If your rotation policy requires a named owner per credential before anything rotates, track that ownership mapping outside the vault; a lifecycle layer like KeyGuardRail reads metadata only, so it never holds the secret value.

What secret structure does the rotation function expect?

Required JSON fields

The managed Lambda template expects the secret to hold four keys: username (the IAM user name), plus the access key fields it creates and updates over time. Store the secret as a single JSON blob, not a plain string, or the function fails on its first run. If you name the secret with the aws/secretsmanager rotation template in mind, keep the JSON flat and avoid extra nested objects that could confuse the function's parsing. For a walkthrough of the same pattern across providers, see our guide on how to manage API keys across multiple cloud providers.

Staging labels during a rotation run

Secrets Manager tracks versions with staging labels rather than separate secrets. Before rotation, AWSCURRENT points at the live key. The function creates a new key, attaches AWSPENDING to it, tests it, then moves AWSCURRENT to the new version and reassigns AWSPREVIOUS to the old one. The old key is deleted after a four-hour window, so apps reading AWSCURRENT swap over while AWSPREVIOUS keeps anything that lagged behind working. Scheduling options, including rate() and cron expressions, are defined in the AWS Secrets Manager user guide.

How do you schedule and trigger rotation for IAM access keys?

Secrets Manager gives you three scheduling options: a fixed interval in days (minimum 4), a rate() or cron() expression, or on-demand rotation via the console or rotate-secret --rotation-token. For IAM access keys, the interval option is usually the right fit because your rotation policy is already expressed in days.

Policy tierInterval settingNotes
30-day30 daysUse for keys touching production billing or payments infrastructure
60-day60 daysCommon default for shared service accounts
90-day90 daysAcceptable for low-blast-radius, read-only keys

A cron expression works when you want rotation pinned to a maintenance window, for example cron(0 3 1 * ? *) to rotate at 03:00 UTC on the first of the month. On-demand rotation covers exceptions: a key that appeared in a Postman collection or a leaked Slack message gets rotated immediately, not at the next scheduled date.

Map the interval to whoever owns the key, not just to the secret. If "Payments platform" owns the Stripe-adjacent keys and "Infrastructure" owns IAM users, each tier needs a named owner and a deadline, which is the core of API key lifecycle management.

What happens to applications using the old key during rotation?

Secrets Manager uses a staged rotation: it creates a second access key for the IAM user, updates the secret, marks the new version AWSCURRENT, and only then deletes the old key. Both keys stay valid during that window, so an app holding the old key keeps working until it re-reads the secret. An IAM user can have at most two access keys at once, which is what makes this two-key dance possible (AWS IAM documentation). The catch: apps only pick up the new key if they fetch the secret again. Anything that cached the old value at boot keeps running on it until restart, so a 90-day rotation policy silently protects nothing if your deploy cycle is longer than that. Track which services re-read secrets and when, and log expiry metadata alongside ownership so the next rotation has a named owner (more on credential lifecycle practices).

How do you troubleshoot a failed IAM access key rotation?

Check the Lambda logs in CloudWatch first. Almost every failure state shows up there with a specific AccessDenied or LimitExceeded message.

Missing permissions. The rotation function needs iam:CreateAccessKey, iam:UpdateAccessKey, and iam:GetAccessKey on the target user, plus Secrets Manager permissions on the secret. If the execution role lacks any of these, rotation fails on the first API call. Fix the role policy, then retry.

Key-per-user limit. IAM allows two active access keys per user. If the user already has two, CreateAccessKey fails before rotation starts. Delete or deactivate an unused key first.

Lambda timeout. The default 3-second timeout is too short for IAM API calls. Raise it to 30 seconds or more.

Stale staging labels. If a previous run failed after creating the new key but before moving AWSCURRENT, the labels are out of sync. Manually move AWSCURRENT to the working version, then trigger rotation again.

When should you rotate IAM access keys with Secrets Manager versus manually?

Use the native rotation template when the key belongs to a standard IAM user and you can accept the template's secret structure and four-step staging (AWSCURRENT, AWSPENDING) flow. Reach for a custom Lambda when the key lives in a SaaS provider like Stripe or GitHub, or when your rotation policy needs extra steps like notifying the owning team.

Skip rotation entirely where you can: short-lived credentials from STS or federated roles expire on their own, and that beats any rotation schedule. The AWS rotation templates documentation lists which templates exist and the exact JSON fields and error paths each expects, so you can check fit before writing a custom function.

The honest rule: rotate what must be long-lived, replace what doesn't.

How do you track rotation deadlines across teams without holding the secret values?

Secrets Manager rotation only covers what lives in Secrets Manager. Your Stripe keys, GitHub PATs, and anything a dev parked in a Postman collection sit outside that Lambda template, so nobody sees a unified expiry calendar. The vault solves storage and rotation mechanics; it does not answer "who owns this key and when does it expire."

The fix is metadata-only monitoring: record owner, provider, and rotation deadline for every credential, and alert on the 30/60/90 day policy without ever touching the secret value. That works whether the credential lives in Secrets Manager, Infisical, or nowhere central at all.

KeyGuardRail does exactly this. You register each key's metadata, assign owners like "Payments platform," and get deadline tracking and an audit trail across AWS plus SaaS providers. Humans stay out of the loop; the values stay in your vault.

FAQ

Does AWS Secrets Manager rotate IAM access keys automatically?

Yes. After you enable rotation on a secret, Secrets Manager runs a managed Lambda template on your chosen schedule. The function creates a second access key for the IAM user, updates the secret, moves staging labels, and retires the old key on the next cycle. The first rotation can run immediately when you enable it.

Can I rotate an IAM access key every 30 days with Secrets Manager?

Yes. Set the interval to 30 days, or use a rate() or cron() expression if you want rotation pinned to a specific window. Thirty days suits keys touching production billing or payments. The minimum interval is 4 days, and IAM's two-key-per-user limit is what allows the staged swap without downtime.

Why did my IAM access key rotation Lambda fail with AccessDenied?

The execution role is missing a required permission. The function needs iam:CreateAccessKey, iam:UpdateAccessKey, and iam:GetAccessKey scoped to the target user, plus secretsmanager:DescribeSecret and secretsmanager:PutSecretValue on the secret. Check the CloudWatch logs for the specific call that failed, fix the role policy, then trigger rotation again.

Do I need a separate secret for each IAM user's access key?

Yes. Each secret holds the username field and the access key values for one IAM user, stored as a flat JSON blob. The rotation function operates on a single user's keys per secret, so one secret per user keeps the execution role least-privileged and the audit trail clear about exactly which keys changed.

How long does the old access key stay valid after rotation?

The old key stays valid during the staged rotation window, roughly four hours, while it holds the AWSPREVIOUS label. Applications that re-read the secret swap to the new key immediately. Anything that cached the old value at boot keeps using it until restart, so verify which services fetch the secret dynamically.