Volume 3 · Chapter 5 — Identity, Security and Compliance
Secrets Management: Secrets Manager and Parameter Store
5.1 Introduction
Applications need configuration and credentials - database passwords, API keys, connection strings - and where those live is a security decision. The wrong answer, embedding them in code or config files, is a leading cause of breaches. The right answer on AWS is a dedicated secrets store accessed at runtime via an IAM role. Two services cover this: AWS Secrets Manager and Systems Manager Parameter Store. Knowing what each is for, and why secrets belong in them rather than in code, is a standard interview topic and a real operational responsibility.
5.2 Why Secrets Don’t Belong in Code
Hard-coding secrets - putting a database password in source, a config file, or an environment variable baked into an image - is dangerous because those secrets leak: into source control history, into logs, into container images, into backups, and they’re rarely rotated and hard to revoke because they’re copied everywhere. A single leaked long-lived credential can grant persistent access. The correct pattern is to store secrets in a managed secrets store and have the application retrieve them at runtime using its IAM role, so the secret is never in the code or image, access to it is controlled and audited, and it can be rotated centrally. This is the direct application of the “no stored long-lived credentials” principle to application configuration.
# The app fetches its DB password at runtime via its role - nothing secret in code or image.
aws secretsmanager get-secret-value --secret-id prod/payments/db \
--query SecretString --output text
# Access is authorized by the app's IAM role and every retrieval is logged.
5.3 AWS Secrets Manager
Secrets Manager is purpose-built for secrets like database credentials and API keys. Its distinguishing feature is built-in automatic rotation: it can rotate a secret on a schedule - for supported databases, it generates a new password, updates the database, and updates the stored secret, so credentials change regularly without manual work or downtime. Secrets are encrypted with KMS, access is controlled by IAM and resource policies, and every retrieval is logged. It carries a per-secret cost, justified when you need managed rotation and the richer secret-management features. For a bank’s database credentials and sensitive API keys, Secrets Manager’s automatic rotation is exactly the capability that keeps credentials fresh and compliant.
5.4 Systems Manager Parameter Store
Parameter Store stores configuration data and secrets as parameters, and it comes in standard (free) and advanced tiers. It holds both plain configuration values and secure (KMS-encrypted) secret values. It doesn’t provide built-in automatic rotation the way Secrets Manager does, but it’s a cost-effective, well-integrated store for general configuration and for secrets where you don’t need managed rotation. Teams often use both: Parameter Store for the large volume of ordinary configuration and simpler secrets, and Secrets Manager specifically for high-value credentials that must be rotated automatically. The choice comes down to whether you need built-in rotation and advanced secret features (Secrets Manager) or a low-cost, general config-and-secret store (Parameter Store).
5.5 Runtime Retrieval Pattern
Regardless of which store, the secure pattern is the same: the application, running under an IAM role, retrieves the secret at runtime from the store, which decrypts it via KMS and returns it only if the role is authorized - and every access is logged. The secret is never written into the application’s source or container image; it exists only in memory at runtime. This means rotating the secret in the store propagates to the application on its next fetch (or refresh), revoking access is a matter of changing the role’s permission, and the audit log shows exactly which identity retrieved which secret when. This runtime-fetch, role-authorized pattern is the entire point - it keeps secrets out of artifacts and under central, audited control.
5.6 Banking Production Scenario
A bank stores its database credentials and payment-gateway API keys in Secrets Manager with automatic rotation enabled, so the database password changes on a schedule with no downtime and no manual handling. General application configuration and lower-sensitivity values live in Parameter Store. Each application retrieves its secrets at runtime using its attached IAM role, which is granted access only to its own secrets - the payments service can read the payments database secret and nothing else. The secrets are encrypted with customer-managed KMS keys, and every retrieval is logged, giving a full audit trail. Because nothing sensitive is ever in code or images, a leaked artifact exposes no credentials, and rotation keeps the live credentials continuously fresh - meeting both security and compliance requirements.
5.7 Troubleshooting: Secret Access Problems
Secret-retrieval failures are usually permission or key issues. “Access denied” fetching a secret means the application’s role lacks permission to read that secret, or lacks permission to use the KMS key that encrypts it - both the secret’s access and the key’s usage must be granted. After enabling rotation, an application that suddenly can’t connect may be caching an old credential and not re-fetching after rotation - the fix is to retrieve (or refresh) the secret at connection time rather than caching it indefinitely, so rotation is picked up. Secrets accidentally left in code or environment variables should be found and moved into the store. The diagnostic pattern is to confirm the role can both read the secret and use its encryption key, and that the app re-fetches secrets so rotation propagates.
Where should application secrets live, and what's the difference between Secrets Manager and Parameter Store?
Application secrets - database passwords, API keys, connection strings - should live in a dedicated managed secrets store and be retrieved by the application at runtime using its IAM role, never hard-coded in source, config files, or container images. The reason is that embedded secrets leak - into source control history, logs, images, and backups - and are rarely rotated and hard to revoke because they’re copied everywhere, so a single leaked long-lived credential can give persistent access; storing them in a secrets store keeps them out of artifacts, puts access under IAM control with full audit logging, and lets them be rotated centrally. On AWS there are two services for this. Secrets Manager is purpose-built for secrets, and its distinguishing feature is built-in automatic rotation: on a schedule it can generate a new credential, update the target (for supported databases it changes the database password and the stored secret together), so credentials rotate regularly with no manual effort and no downtime; secrets are encrypted with KMS, access is controlled by IAM and resource policies, every retrieval is logged, and it carries a per-secret cost justified by that managed rotation and richer feature set. Systems Manager Parameter Store stores configuration and secrets as parameters in a free standard tier and an advanced tier; it holds both plain config values and secure KMS-encrypted secret values, integrates well, and is very cost-effective, but it doesn’t provide built-in automatic rotation the way Secrets Manager does. So the difference is essentially managed rotation and advanced secret features versus a low-cost general configuration-and-secret store. The way I choose: I use Secrets Manager for high-value credentials that must be rotated automatically - database and payment-gateway credentials - because automatic rotation is exactly what keeps them fresh and compliant, and I use Parameter Store for the larger volume of ordinary configuration and simpler secrets where I don’t need managed rotation and want to minimize cost. Many teams use both together for exactly that split. But the most important point regardless of which service is the pattern: the application fetches secrets at runtime under its IAM role, granted access only to its own secrets, with the values encrypted by KMS and every access logged - so secrets never sit in code or images, rotation and revocation are central, and there’s a complete audit trail, which is the standard a bank must meet.
Chapter Revision Notes
- Never hard-code secrets - they leak into source, logs, images, and backups and are rarely rotated; store them and fetch at runtime via an IAM role.
- Secrets Manager: purpose-built for secrets with built-in automatic rotation; KMS-encrypted, IAM-controlled, logged; per-secret cost.
- Parameter Store: config and secrets as parameters, standard (free) and advanced tiers; no built-in rotation; cost-effective for general config.
- Choose Secrets Manager for high-value credentials needing rotation; Parameter Store for general config and simpler secrets - often both.
- Runtime-fetch, role-authorized, KMS-encrypted, logged pattern keeps secrets out of artifacts and under central audited control.