teluzia.Cloud Engineer · Day 73
CHAPTER 11 · AWS SECURITY AND GOVERNANCE

Secrets Manager and secret rotation concepts

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Secrets Manager is a controlled credential locker; rotation is exchanging the lock and updating authorized users in a coordinated sequence. Secrets Manager stores secret values with version metadata and access controls. Applications retrieve secrets using an authorized identity instead of embedding them in source. Retrieval should minimize unnecessary calls and avoid writing values into logs, errors, screenshots, or shell history. Rotation changes credentials in both the secret store and the dependent service. Supported managed rotation or a custom Lambda workflow must create, set, test, and finish the new secret appropriately. Merely changing a stored string does not update a database user.

Think of it this way

Secrets Manager is a controlled credential locker; rotation is exchanging the lock and updating authorized users in a coordinated sequence.

TOPIC 01 / 03Step by step

Secret storage and retrieval

Secrets Manager stores secret values with version metadata and access controls. Applications retrieve secrets using an authorized identity instead of embedding them in source. Retrieval should minimize unnecessary calls and avoid writing values into logs, errors, screenshots, or shell history. For example, an application uses an execution role to retrieve a database credential at runtime rather than commit its password in config.py.

WORKED EXAMPLE
An application uses an execution role to retrieve a database credential at runtime rather than commit its password in config.py.

A web application starts with an AWS workload identity rather than a database password in its image. It calls Secrets Manager for a named secret, receives the permitted current value, and uses it to establish a database connection. The secret retrieval path and the database authentication path can fail independently, so log only identifiers and error categories needed to distinguish them.

A secret is sensitive configuration requiring controlled access. A secret version is one stored value with version metadata. Caching retains a retrieved value temporarily to reduce latency and calls. Caching improves efficiency but creates refresh responsibilities when the value changes. Avoid indefinitely persisting a credential in a local file or printing it on startup. Least privilege should scope retrieval to the required secret, with any relevant KMS permissions considered. Moving a password out of source is progress, but it does not solve compromised workload identity, excessive retrieval access, or logs that reveal the credential after retrieval.

Why this matters

An application uses an execution role to retrieve a database credential at runtime rather than commit its password in config.py.

A common trap

Do not overlook this operational distinction: Retrieval should minimize unnecessary calls and avoid writing values into logs, errors, screenshots, or shell history.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Secret storage and retrieval

Secrets Manager stores secret values with version metadata and access controls. Applications retrieve secrets using an authorized identity instead of embedding them in source. Retrieval should minimize unnecessary calls and avoid writing values into logs, errors, screenshots, or shell history. For example, an application uses an execution role to retrieve a database credential at runtime rather than commit its password in config.py.

WORKED EXAMPLE
An application uses an execution role to retrieve a database credential at runtime rather than commit its password in config.py.

A web application starts with an AWS workload identity rather than a database password in its image. It calls Secrets Manager for a named secret, receives the permitted current value, and uses it to establish a database connection. The secret retrieval path and the database authentication path can fail independently, so log only identifiers and error categories needed to distinguish them.

A secret is sensitive configuration requiring controlled access. A secret version is one stored value with version metadata. Caching retains a retrieved value temporarily to reduce latency and calls. Caching improves efficiency but creates refresh responsibilities when the value changes. Avoid indefinitely persisting a credential in a local file or printing it on startup. Least privilege should scope retrieval to the required secret, with any relevant KMS permissions considered. Moving a password out of source is progress, but it does not solve compromised workload identity, excessive retrieval access, or logs that reveal the credential after retrieval.

Why this matters

An application uses an execution role to retrieve a database credential at runtime rather than commit its password in config.py.

A common trap

Do not overlook this operational distinction: Retrieval should minimize unnecessary calls and avoid writing values into logs, errors, screenshots, or shell history.

Rotation coordination

Rotation changes credentials in both the secret store and the dependent service. Supported managed rotation or a custom Lambda workflow must create, set, test, and finish the new secret appropriately. Merely changing a stored string does not update a database user. For example, a newly generated password must work against the database before it becomes the current application credential.

WORKED EXAMPLE
A newly generated password must work against the database before it becomes the current application credential.

A database password rotation starts by preparing a new candidate credential. The rotation process updates the database user or alternate user according to the chosen strategy, then tests a connection with the candidate. Only after it passes should the new version become current. If promotion happens first, applications can retrieve a value the database rejects.

A pending version is the candidate under rotation. Promotion changes the label used for normal retrieval. Rotation is coordination between the store and the dependent service, not merely generation of a random string. Managed rotation availability and custom-function requirements depend on the service and secret type. Multi-user strategies can reduce disruption but add identity lifecycle complexity. Single-user changes may affect existing connection and refresh behavior differently. Test network reachability and database rights for the rotation mechanism as well as its Secrets Manager access; a function allowed to store a secret cannot rotate a database it cannot reach or administer.

Why this matters

A newly generated password must work against the database before it becomes the current application credential.

A common trap

Do not overlook this operational distinction: Merely changing a stored string does not update a database user.

Versions and application refresh

Version staging labels identify current, previous, or pending secret versions. Applications with cached credentials need a refresh strategy when rotation occurs. Recovery should account for failed rotation and connection behavior, while preserving limited access to old versions when operationally necessary. For example, aWSCURRENT is used by normal retrieval; a connection failure after rotation may require refreshing an application’s cached credential.

WORKED EXAMPLE
AWSCURRENT is used by normal retrieval; a connection failure after rotation may require refreshing an application’s cached credential.

A long-running application retrieved a credential at 08:00. Rotation completes at 08:30, but its cached value still represents the earlier version. Existing connections may continue working while a newly created connection fails, depending on database behavior. The application needs a deliberate refresh path rather than interpreting every connection error as a permanent infrastructure outage.

A staging label associates a meaning such as current or pending with a version. A cache lifetime bounds how long the application retains a retrieved value. Connection pooling reuses database connections and can obscure when credentials are actually checked. A practical strategy may refresh on a bounded interval or one recognized authentication failure, then retry safely without looping forever. Do not dump the old and new passwords into logs to compare them. Version identifiers and timing provide safer evidence. Recovery also needs a defined policy for failed rotation and previous credentials; blindly reverting the store without coordinating the database can create another mismatch.

Why this matters

AWSCURRENT is used by normal retrieval; a connection failure after rotation may require refreshing an application’s cached credential.

A common trap

Do not overlook this operational distinction: Recovery should account for failed rotation and connection behavior, while preserving limited access to old versions when operationally necessary.

KEEP THESE WITH YOU

Today’s takeaways

Secret storage and retrieval: Secrets Manager stores secret values with version metadata and access controls. Applications retrieve secrets using an authorized identity instead of embedding them in source. Retrieval should minimize unnecessary calls and avoid writing values into logs, errors, screenshots, or shell history.

Rotation coordination: Rotation changes credentials in both the secret store and the dependent service. Supported managed rotation or a custom Lambda workflow must create, set, test, and finish the new secret appropriately. Merely changing a stored string does not update a database user.

Versions and application refresh: Version staging labels identify current, previous, or pending secret versions. Applications with cached credentials need a refresh strategy when rotation occurs. Recovery should account for failed rotation and connection behavior, while preserving limited access to old versions when operationally necessary.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed