Data Protection · Topic 6 of 7

Secrets Manager and Parameter Store

Store and rotate credentials with Secrets Manager and Parameter Store, compare features, control access and inject secrets into applications safely.

  • 5 min
In a nutshell
  • Secrets Manager rotates secrets natively with Lambda, with managed rotation for supported databases. Parameter Store does not rotate.
  • Version stages are AWSCURRENT, AWSPENDING and AWSPREVIOUS.
  • Cross account access to a secret needs a resource policy, and a customer managed KMS key that the other account can use.

What it is

Secrets are values that grant access, such as database passwords, API keys and tokens. They must not live in code, images or plain environment variables, and they should be rotated.

AWS offers two main stores. AWS Secrets Manager is built for secrets with rotation, and Systems Manager Parameter Store is a general configuration store that can also hold encrypted values.

Applicationrole with accessGetSecretValueSecrets Managerencrypted with KMSrotation LambdaDatabasepassword changes

How it works

Secrets Manager

  • Storage. Secrets are encrypted with a KMS key, either the AWS managed key for Secrets Manager or a customer managed key.
  • Rotation. Secrets Manager can rotate a secret on a schedule using a Lambda function. For many databases, such as Amazon RDS, managed rotation or ready made rotation functions exist.
  • Versions. Each value has a version with staging labels. AWSCURRENT is the live value, AWSPENDING is a new value during rotation, and AWSPREVIOUS is the last one.
  • Access control. IAM policies on the caller, a resource policy on the secret, and the key policy of the KMS key all apply. For cross account use, add a resource policy and use a customer managed key.
  • Replication. A secret can be replicated to other Regions for disaster recovery.
  • Audit. CloudTrail records GetSecretValue and other calls.
# AWS CLI: read the current value of a secret
aws secretsmanager get-secret-value --secret-id prod/app/db \
  --query SecretString --output text

How rotation works

Rotation follows four steps: create a new secret version, set the new credential in the database, test it, and finish by moving the AWSCURRENT label. The rotation function needs network access to both the database and the Secrets Manager endpoint, so a function in a VPC needs a route or an interface endpoint.

StrategyHowTrade-off
Single userChanges the password of one database userSimple, but connections can fail briefly during the change
Alternating usersSwitches between two users, updating the password of the one not in useAvoids downtime, needs two users and an admin secret

With Amazon RDS you can also let the service manage the master user password in Secrets Manager, which rotates it automatically and removes the need to handle it.

Parameter Store

Parameter Store keeps parameters in a hierarchy, such as /prod/app/db-url. It has three types.

TypeContent
StringPlain text configuration
StringListComma separated values
SecureStringEncrypted with a KMS key

There are standard and advanced tiers, which differ in the number of parameters, size and features such as parameter policies for expiry notifications. Parameter Store has no built in secret rotation, and standard parameters have no additional charge for storage.

Comparing the two

FeatureSecrets ManagerParameter Store
PurposeSecrets and credentialsConfiguration and some secrets
Automatic rotationYes, built inNo, build your own
Cross Region replicationYesNot built in
CostCharged per secret and per callStandard tier has no storage charge
Cross account sharingResource policy on the secretMore limited, mainly for advanced parameters
EncryptionAlways, KMSSecureString type only

Choose Secrets Manager for credentials that need rotation, cross account sharing or replication. Choose Parameter Store for application configuration and for secrets that are static and low in value or cost sensitive.

Getting secrets into applications

  • ECS. Reference the secret in the task definition secrets field, and the agent injects it at start using the task execution role.
  • EKS. Use the Secrets Store CSI driver to mount secrets, with a pod identity for access.
  • Lambda. Fetch at runtime with a role, and cache the value. Avoid long lived plain environment variables.
  • CloudFormation. Use a dynamic reference, such as {{resolve:secretsmanager:prod/app/db:SecretString:password}}, so the value is never in the template.
  • EC2. Read with the instance role at startup, not from user data.
Container taskexecution rolefetchesSecrets Managersecret valueinjectsEnvironmentat start only

Good practice

  • Use one secret per purpose, and name them with a path.
  • Give each workload read access to its own secrets only, with resource ARNs in the IAM policy.
  • Use a customer managed key when you need separate access control or cross account use.
  • Alarm on unusual GetSecretValue activity, and on rotation failures.
  • Scan code and repositories for hard coded secrets, and revoke any that are found.
  • Prefer roles and temporary credentials over secrets where possible, since no secret is better than a rotated one.

What to remember for the exam

  • Secrets Manager rotates secrets natively with Lambda, with managed rotation for supported databases. Parameter Store does not rotate.
  • Version stages are AWSCURRENT, AWSPENDING and AWSPREVIOUS.
  • Cross account access to a secret needs a resource policy, and a customer managed KMS key that the other account can use.
  • Rotation functions need network access to both the database and the Secrets Manager endpoint.
  • Alternating users rotation avoids downtime.
  • RDS can manage the master user password in Secrets Manager.
  • Parameter Store SecureString uses KMS, and has standard and advanced tiers.
  • Inject secrets through the platform at startup, and never put them in code, images or user data.
Exam tip

A question that mentions "rotate the database credentials automatically every 30 days" is almost always Secrets Manager.

Common mistakes

Using the AWS managed key for cross account secrets. The other account cannot use it, so a customer managed key is needed.

Putting a rotation Lambda in a VPC without endpoints. It cannot reach Secrets Manager and rotation fails.

Storing secrets in environment variables of a Lambda function. They show in the console and in configuration exports.

Reading the secret on every request. It adds cost and latency, so cache it with a short lifetime.

Watch out

A secret deleted from Secrets Manager has a recovery window, but if you force immediate deletion there is no way to recover it.

Check yourself

  • Which store supports automatic rotation of database credentials?

    AWS Secrets Manager, using a rotation Lambda function or managed rotation.

  • Why does a rotation Lambda in a VPC sometimes fail?

    It cannot reach the Secrets Manager endpoint or the database, so it needs a route, NAT or an interface endpoint.

  • What does the AWSCURRENT label mean?

    It marks the secret version that is the live value returned by default.

Topic 6 of 7 in Data Protection

Test yourself on Data Protection

The full AWS SCS-C03 question bank has 858 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.