AWS Builder Center

How AWS Secrets Manager and Lambda Eliminate Manual Key Rotation and risk associated

How AWS Secrets Manager and a rotation Lambda replace manual key rotation with an automated, tested, auditable process covering key governance basics

How AWS Secrets Manager and Lambda Eliminate Manual Key Rotation and risk associated 
Manual key rotation usually fails for a pretty ordinary reason: it depends on a person remembering to do a repetitive, low-visibility, high-stake task on schedule, forever.
Somewhere in a wiki page, a ticket, or an old chat thread there's a note that says "rotate this credential every 90 days." Then the Tickets backlog gets louder. The owner changes teams. The runbook goes stale. The key finally gets rotated when an audit finds it, when it expires, or when production breaks at 2 a.m.
AWS Secrets Manager plus a rotation Lambda changes the shape of that problem. Instead of treating rotation as a calendar reminder, you turn it into a system behavior: scheduled, scoped, tested, logged, repeatable.

This post walks through what key governance means in an AWS environment, how Secrets Manager and Lambda rotate secrets end to end, where the availability tradeoffs sit, two attack scenarios that automated rotation helps contain, a practical pattern for short-lived private TLS certificates, and how all of this maps back to NIST's key-management expectations.

Key governance is not just "store secrets somewhere"

In practice, key governance comes down to a handful of engineering guarantees. Every secret needs a defined owner and known consumers. Every secret needs a rotation cadence, an expiry expectation, and a rotation path that's actually been tested rather than assumed to work. Only the identities that need a secret should be able to read it. If a credential leaks, its useful lifetime should be bounded rather than open-ended. And access, rotation, and version changes all need to be traceable after the fact.
Secrets Manager gives you the encrypted storage, version labels, IAM and resource policies, rotation metadata, and CloudTrail visibility to satisfy most of that. Lambda gives you the execution layer that can go update the real target system, whether that's a database, a cache user, an Active Directory credential, a private certificate distribution process, or a custom service that happens to support programmatic credential updates.
The real shift here is that rotation stops being a person with broad access manually changing a password. It becomes a narrowly scoped function doing one job, on one secret or a small family of secrets, with logs and version history behind it.

How Secrets Manager rotation works

When rotation runs through a Lambda function, Secrets Manager calls that same Lambda several times during a single rotation, passing it the secret identifier, a client request token, and a rotation step. AWS's own rotation templates name four phases. createSecret generates or requests the new credential and stores it as AWSPENDING. setSecret applies that pending credential to the target service. testSecret proves the pending credential actually works before it gets promoted. finishSecret moves AWSCURRENT to the new version, and the previous version becomes AWSPREVIOUS.
This staged approach is what makes rotation safer than just changing a value and hoping for the best. A failed testSecret should stop promotion cold. The system keeps enough version state to know which version is current, previous, and pending, instead of relying on someone to track that by hand.
One thing worth knowing: the version labels don't automatically guarantee the old credential keeps working in the target service the whole time. For single-user database rotation, AWS documents a short window where the password has already changed in the database but the secret's version label hasn't moved yet. Open connections aren't dropped during that window, but new calls can get denied, which is why applications should build in retries. For workloads that need higher availability, the alternating-users strategy is the better fit: the Lambda swaps between two database users so a valid one is always available during rotation.
The rotation Lambda's role should be able to read and update only the secret it rotates, plus whatever target-service permissions it needs to actually change the credential. If the secret uses a customer-managed KMS key instead of aws/secretsmanager, scope decrypt permissions down to the secret's encryption context where you can.
The secret's own resource policy can restrict who reads it and where those calls are allowed to come from. For private workloads, it's worth denying GetSecretValue unless the request comes through an expected VPC endpoint or VPC condition, and using BlockPublicPolicy or resource policy validation to catch anything broader than intended. 
This is really the governance payoff: fewer humans holding broad privileges, clearer ownership lines, and much better evidence when security or an auditor asks who touched a credential and when.

Case study pattern: short-lived private TLS certificates

Here's a practical pattern for internal TLS certificates where the application itself needs the certificate material directly, say an internal service running on ECS, EC2, Kubernetes, or an on-prem endpoint managed through Systems Manager.
Use AWS Private CA directly to issue short-lived end-entity certificates. Private CA lets you choose the validity period for directly issued certificates, as long as the end-entity certificate doesn't outlive the issuing CA itself. That's different from ACM-managed private certificates, which come with a fixed 13-month validity and ACM-managed renewal.
The clean version of this pattern looks like: AWS Private CA issues the certificate from a CSR, the private key gets generated and stored carefully by your rotation workflow, Secrets Manager stores the certificate bundle and private key as a versioned secret, and the rotation Lambda renews before expiry, deploys to targets, runs a TLS validation, and only promotes the pending version once that passes. Old material gets retired after the overlap window, and revocation is only useful if your clients actually check OCSP or CRLs and the CA was configured for revocation before issuance.
The detail that actually matters is the schedule. If certificate validity is 14 days, don't schedule renewal on day 14. Schedule it earlier, say day 12, so there's room to deploy, test, retry, and roll back if something goes wrong before expiry.
The two-week cycle in practice
Day
Event
Day 0
Private CA issues a 14-day certificate. The bundle is stored as AWSCURRENT and deployed.
Day 12
Secrets Manager's rotation schedule invokes the Lambda during the rotation window.
Day 12
Lambda creates a new certificate, saves it as AWSPENDING, deploys it and checks TLS.
Day 12
If validation passes, finishSecret promotes the replacement to AWSCURRENT.
Day 13–14
The old certificate stays available in the previous version for rollback or drain.
Day 14
The old certificate expires naturally, or gets revoked if revocation checking is part of your PKI design.
A practical starting point
If you're setting this up for the first time, start with AWS's own rotation templates for supported database and service secrets rather than writing rotation logic from scratch. Use the alternating-users strategy for database workloads that need the highest availability. Test rotation in non-production before shortening the interval. Have applications retrieve AWSCURRENT at runtime with sensible caching and retries built in. Watch CloudTrail for Secrets Manager API calls and rotation failures. Keep Lambda logs free of secret values. And prefer IAM roles and temporary credentials over long-lived IAM access keys wherever you have the choice.
None of this makes secrets impossible to leak. It doesn't. What it does is shrink how long a leaked credential actually matters, and it turns the rotation process itself into something boring, repeatable, and auditable.
That's what good key governance looks like in practice: fewer heroic reminders, fewer expired certificates, fewer forgotten access keys, and more of the security behavior enforced by the platform rather than by someone's memory.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article