Choosing Between Secrets Manager and Parameter Store
This lesson explains how AWS Secrets Manager and AWS Systems Manager Parameter Store both store secrets and configuration securely, and how they differ in rotation, limits and cost.
Learning outcomes
After completing this lesson, you will be able to:
- Choose between Secrets Manager and Parameter Store for a secret or configuration value.
- Describe Parameter Store features such as hierarchies, SecureString parameters and public parameters.
- Explain why values should be fetched once per execution environment and cached.
Side by side
Secrets Manager and Parameter Store both store values securely, encrypt them with KMS and control access with IAM, and both can be referenced from CloudFormation, ECS task definitions and CodeBuild. They differ in what they are designed for.
Secrets Manager is built for credentials that must change regularly. Its main feature is automatic rotation: on a schedule, a rotation function creates a new password, updates it in the database and stores it in the secret, while applications keep reading the current version. AWS provides ready-made rotation functions for Amazon RDS, Aurora, Redshift and DocumentDB credentials, RDS, Aurora and Redshift can also manage their administrator password in Secrets Manager with managed rotation that needs no function, and a custom Lambda function rotates any other kind of secret. A secret can hold up to 64 KB, can be replicated to other Regions and can have a resource policy that lets another account read it. Each secret has a monthly charge.
Parameter Store, part of Systems Manager, is built for configuration. Values are plain String or StringList parameters, or SecureString parameters encrypted with KMS. Names form a hierarchy, such as /orders/prod/db-url, so an application can read all its settings with one call and IAM policies can grant access by path. Standard parameters, up to 4 KB, cost nothing; advanced parameters allow 8 KB and policies such as expiry dates. There is no built-in rotation. The following table summarises the differences.
String, StringList, KMS-encrypted SecureStringParameter Store features
Parameter Store provides features for organising parameters and obtaining values published by AWS. The following list describes them.
- Hierarchies: names such as
/app/prod/db-urllet you fetch a whole environment's configuration by path. - Public parameters: AWS publishes values such as the latest Amazon Linux AMI ID, often referenced from CloudFormation and launch templates.
Reading values from code
Both services integrate with CloudFormation, Lambda, ECS and CodeBuild. Fetch values once per execution environment and cache them rather than calling the API on every request.
import json, boto3
ssm = boto3.client("ssm")
secrets = boto3.client("secretsmanager")
API_URL = ssm.get_parameter(Name="/orders/prod/api-url")["Parameter"]["Value"]
FLAGS = ssm.get_parameters_by_path(Path="/orders/prod/flags/", Recursive=True, WithDecryption=True)["Parameters"]
DB = json.loads(secrets.get_secret_value(SecretId="orders/db")["SecretString"]) # {"username": ..., "password": ...}In Lambda, the Parameters and Secrets Lambda extension (or the Powertools parameters utility) serves both from a local cache that refreshes on a TTL, so rotated secrets are picked up. Requests use the function's own session token:
curl -s -H "X-Aws-Parameters-Secrets-Token: $AWS_SESSION_TOKEN" \
"http://localhost:2773/secretsmanager/get?secretId=orders/db"Storing an application's configuration
An application uses several configuration values with different requirements. The following table identifies the appropriate store for each value and the reason for the choice.
| Value | Store | Why |
|---|---|---|
| Database password, rotated every 30 days | Secrets Manager | Automatic rotation |
| Third-party API key, rotated by hand yearly | Parameter Store SecureString (or Secrets Manager) | Encrypted; no rotation needed; cheaper |
Feature setting /orders/prod/maxItems | Parameter Store String | Plain configuration, free |
| Feature flag rolled out gradually with rollback | AppConfig | Deployment strategies and alarms |
| Secret shared with another account | Secrets Manager | Resource policies |
Whichever store is used, the function caches values (for example with the Parameters and Secrets extension) rather than calling the API on every invocation, which avoids throttling and cost.
A database password must rotate automatically every 30 days. Which service should store it?
Show answer
Secrets Manager, which has built-in rotation through a Lambda function, including templates for RDS. Parameter Store SecureString parameters have no built-in rotation.
Exam Tips
Remember for the exam
- Database credentials that must rotate automatically belong in Secrets Manager.
- Cheap, hierarchical configuration values belong in Parameter Store.
- To cache secrets in Lambda with automatic refresh, use the Parameters and Secrets Lambda extension.
- To use the latest AMI ID in templates, reference a Parameter Store public parameter.