Lesson 3 of 3 Encryption in Transit and Secrets Management

Storing Secrets with Secrets Manager and Parameter Store

This lesson explains how AWS Secrets Manager and Parameter Store store database passwords, API keys and tokens securely, removing a common audit finding of secrets in code, AMIs or environment files.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe Secrets Manager features.
  • Explain the steps of secret rotation.
  • Choose between Secrets Manager and SecureString parameters.

AWS Secrets Manager

Secrets Manager stores secrets as encrypted values (JSON key-value pairs or text, up to 64 KB) using a KMS key, controls access with IAM and resource-based policies (for cross-account access), and records access in CloudTrail. Secrets have versions with staging labels AWSCURRENT, AWSPENDING and AWSPREVIOUS. Replica secrets copy a secret to other Regions for multi-Region applications and DR. Applications retrieve secrets at runtime with GetSecretValue, ideally through caching clients or the Lambda Parameters and Secrets extension; ECS and EKS inject secrets into containers, and CloudFormation uses dynamic references.

Rotation

Rotation changes a secret on a schedule (as often as every four hours) using a Lambda rotation function that runs four steps: createSecret, setSecret (change the password in the database), testSecret and finishSecret (move AWSCURRENT). For RDS, Aurora, Redshift and DocumentDB credentials, AWS provides rotation function templates, and managed rotation is available for secrets that services such as RDS create themselves (for example the master password when Manage master credentials in AWS Secrets Manager is selected). The alternating users strategy rotates between two database users so connections never fail during rotation. A rotation function in a VPC needs network access both to the database and to the Secrets Manager endpoint (an interface endpoint or NAT), and its role needs permission for the secret and its KMS key; missing endpoints are the most common rotation failure, visible in the function's CloudWatch logs.

The following diagram shows the four rotation steps.

Secrets Manager rotation. On a schedule, as often as every four hours, a rotation Lambda function runs four steps: createSecret makes a new value labelled AWSPENDING, setSecret changes the password in the database, testSecret checks it, and finishSecret moves the AWSCURRENT label to it.
Applications that fetch the secret at run time pick up the new value without redeploying.
Put in order

A rotation cycle

Exam skills 4.2.4

Put the steps of a Secrets Manager rotation in order.

Log in to try this activity Interactive activities are free with an account.

Parameter Store SecureString

Parameter Store SecureString parameters are encrypted with KMS and suit configuration values and secrets that do not need rotation. Parameter Store is cheaper (the standard tier is free), supports hierarchies and versions, and can reference Secrets Manager secrets through the /aws/reference/secretsmanager/ path, but has no built-in rotation, no cross-account resource policies (except for advanced-tier parameter sharing with AWS RAM) and no replica secrets. The following table compares the two services.

Secrets Manager
Automatic rotationYes, with Lambda (templates for databases)
Cross-Region replicationReplica secrets
Cross-account accessResource-based policy
Maximum size64 KB
CostPer secret per month plus API calls
Typical useDatabase credentials, API keys needing rotation
Parameter Store SecureString
Automatic rotationNo
Cross-Region replicationNo
Cross-account accessAdvanced parameters shared with AWS RAM
Maximum size4 KB (standard) / 8 KB (advanced)
CostStandard tier free; advanced charged
Typical useConfiguration and non-rotating secrets
Sort into groups

Secrets Manager or Parameter Store?

Exam skills 4.2.4

Choose where to store each secret.

Log in to try this activity Interactive activities are free with an account.
Worked example

Removing hard-coded passwords

A security review finds a database password in an application's environment file baked into the AMI. The team creates a Secrets Manager secret with the RDS rotation template using the alternating users strategy and a 30-day schedule, places the rotation function in the database's VPC with a Secrets Manager interface endpoint, grants the application's instance role secretsmanager:GetSecretValue on the secret and kms:Decrypt on its key, and changes the application to read the secret at start-up with a caching client. The password is rotated immediately, invalidating the leaked value, and the AMI is rebuilt without the file.

Check yourself

Which rotation strategy avoids connection failures while a password changes?

Show answer

Alternating users rotation.

Exam Tips

Remember for the exam

  • Secrets Manager rotates secrets with Lambda functions; Parameter Store does not rotate.
  • Rotation functions in a VPC need routes to the database and the Secrets Manager endpoint.
  • Alternating users rotation avoids connection failures during rotation.
  • Replica secrets support multi-Region applications.
  • Use SecureString for non-rotating configuration values at lower cost.