AWS Secrets Manager
Storing and rotating secrets, KMS envelope encryption of secret values, replication, and how it differs from Parameter Store.
Exam tasks: 5.3.1 (design management and rotation of secrets for workloads)
The decision: where does each credential live, how does it rotate without an outage, who can read it from which account, and how does the application fetch it without the value ending up in code, images or logs?
Secrets Manager stores credentials, API keys and other secrets, controls access with IAM and resource policies, and rotates them on a schedule.
Which one to use
| Secrets Manager | Parameter Store SecureString | |
|---|---|---|
| Built-in rotation | Yes: managed rotation or a Lambda function on a schedule | No; build your own with EventBridge and Lambda |
| Max value size | 64 KB | 4 KB standard, 8 KB advanced tier |
| Encryption | Always, with aws/secretsmanager or a customer managed key | KMS, with aws/ssm or a customer managed key |
| Resource-based policy | Yes, per secret | No; advanced parameters can be shared through AWS RAM |
| Cross-account read | Resource policy + customer managed key | RAM share of an advanced parameter + key access |
| Multi-Region | Replica secrets that stay in sync | No; copy per Region |
| Versioning | Staging labels (AWSCURRENT, AWSPENDING, AWSPREVIOUS) | Numbered versions and labels |
| Cost | Per secret per month, plus API calls | Standard tier free |
| Good for | Database, API and third-party credentials that must rotate | Config values, feature flags, low-change secrets |
- Parameter Store can reference a Secrets Manager secret (a parameter name that starts with
/aws/followed byreference/secretsmanager/and the secret name), so tools that only read parameters can still get rotated secrets. - Prefer no secret at all: IAM roles for AWS APIs, IAM database authentication for RDS and Aurora, and Secrets Manager only where a password is unavoidable.
Core facts
| Item | Fact |
|---|---|
| Encryption | Envelope encryption. Each secret value change gets a new 256-bit AES data key from GenerateDataKey. Only symmetric KMS keys. Default is aws/secretsmanager |
| What is not encrypted | Secret name, description, rotation settings, KMS key ARN and tags |
| Encryption context | SecretARN and SecretVersionId, usable in key policy conditions and in audit |
| Cross-account | Resource policy on the secret plus a customer managed key. The AWS managed key cannot be used across accounts |
| Rotation | Managed rotation (no Lambda) for service-managed secrets, or a Lambda function with steps create_secret, set_secret, test_secret, finish_secret |
| Version stages | AWSCURRENT, AWSPREVIOUS, AWSPENDING. A new version gets AWSPENDING during rotation |
| Replication | Replicate to other Regions with a replica KMS key. Rotation on the primary propagates to replicas. A replica can be promoted to standalone |
| Parameter Store link | Read a secret through GetParameter using a name that starts with /aws/ followed by reference/secretsmanager/ and the secret name. IAM on the secret still applies |
Limits
| Limit | Value |
|---|---|
| Secret value size | 65,536 bytes |
| Versions per secret | 100 |
| Secrets per Region | 500,000 |
| Resource policy length | 20,480 characters |
| Staging labels per secret | 20 |
GetSecretValue rate | 10,000 per second per Region |
Avoid calling PutSecretValue or UpdateSecret more often than once every 10 minutes sustained. Secrets Manager prunes unlabeled versions beyond 100, but never those under 24 hours old.
Rotation
Managed rotation
- Services that own the credential rotate it for you, with no Lambda function: for example RDS and Aurora with managed master user passwords, Redshift admin passwords, and some partner-held secrets.
- For RDS, set
ManageMasterUserPasswordand the password lives in Secrets Manager, rotating every 7 days by default. Nobody ever sees it in the console or in CloudFormation.
Rotation with a Lambda function
The function is called four times per rotation, one per step:
AWSPENDING.AWSCURRENT to the new version; the old one becomes AWSPREVIOUS.- Schedules can be as frequent as every 4 hours, with a rotation window during which the rotation may run.
- The function needs a network path to both the database and the Secrets Manager endpoint. In a private subnet with no NAT gateway, add an interface VPC endpoint for Secrets Manager. This is the most common cause of "rotation times out".
- It also needs
kms:Decryptandkms:GenerateDataKeyon the secret's key.
| Strategy | How it works | Trade-off |
|---|---|---|
| Single user | Changes the password of the one user the app uses | Brief window where connections using the old password fail; simplest |
| Alternating users | Two users (for example app and app_clone); each rotation updates the idle one and switches | No downtime; needs a separate admin secret with rights to change the other users |
- Avoid calling
PutSecretValueorUpdateSecretmore often than once every 10 minutes sustained. Secrets Manager prunes unlabeled versions beyond 100, but never those under 24 hours old.
Exam signal
"Rotate database credentials automatically with no downtime for a high-traffic application" means the alternating users strategy, or managed master user passwords for the master account. "Rotation fails with a timeout" in a private subnet points to a missing Secrets Manager VPC endpoint or NAT route.
Exam signal
"Rotate RDS credentials every 30 days with no code change" means Secrets Manager rotation, and the app should fetch the secret at runtime. "Only the Lambda in account B may read the secret" means a resource policy plus a customer managed KMS key.
Rotating the secret but not the app
Rotation only helps if the application reads the secret at run time. Applications that copy the password into a
config file at deploy time break at the next rotation. Use the caching client, the Lambda extension or native
integrations so the app picks up AWSCURRENT on its own.
Cross-account access
To let account B read a secret in account A:
- Resource policy on the secret in A allows the role in B
secretsmanager:GetSecretValue. - The secret is encrypted with a customer managed key, and its key policy allows the role in B
kms:Decrypt(usually withkms:ViaServiceset to Secrets Manager in that Region). - The IAM policy on the role in B allows both actions on the secret and key ARNs.
- Secrets encrypted with
aws/secretsmanagercan't be read cross-account, because you can't edit that key's policy. Re-encrypt with a customer managed key first. - Turn on
BlockPublicPolicyso a resource policy that grants broad access is rejected, and let IAM Access Analyzer flag secrets shared outside the organization.
Getting secrets into workloads safely
| Workload | Recommended way |
|---|---|
| Lambda | AWS Parameters and Secrets Lambda Extension (local cache over HTTP), not environment variables |
| ECS | secrets in the task definition referencing a Secrets Manager or Parameter Store ARN; injected at start, the task execution role needs access |
| EKS | Secrets Store CSI Driver with the AWS provider (ASCP), with EKS Pod Identity or IRSA for access |
| EC2 | Instance role plus SDK or Secrets Manager Agent; never in user data |
| CloudFormation | Dynamic references (resolve:secretsmanager:...) or ManageMasterUserPassword, never plaintext parameters |
| Any app | Client-side caching libraries to cut latency, cost and throttling |
Places secrets must never be:
- Source code and repositories. Run secret scanning (Amazon Inspector code security, or pre-commit hooks such as git-secrets), and treat anything already committed as compromised: rotate it.
- EC2 user data. Anyone with
ec2:DescribeInstanceAttributecan read it, and it's visible from inside the instance through the metadata service. - Lambda environment variables. With the default key, anyone allowed
lambda:GetFunctionConfigurationsees them in plaintext, and they can't rotate. Fetch the secret at run time instead. - Container images and AMIs. Anyone who pulls them gets the secret.
- Logs. Mask them with CloudWatch Logs data protection.
Scenarios
The function can't reach the Secrets Manager API to write the AWSPENDING version, so rotation times out at the first step. An interface endpoint gives it a private path. A longer timeout doesn't create a route, making the database public is a security regression, and CreateGrant isn't needed for rotation.
Cross-account secret access needs a KMS key the other account can use, which rules out the AWS managed key. Its policy can't be edited. Replicas stay in the owning account. BlockPublicPolicy restricts policies rather than granting access.
Secrets Manager provides rotation, and fetching at run time keeps the value out of user data and function configuration, which read-only principals can view. Base64 is encoding, not encryption. A String parameter is stored in plaintext and has no rotation. A password baked into an AMI is exposed to anyone who can launch it and can't rotate.
Related
- KMS keys and envelope encryption
- KMS key policy, IAM and grants
- Sensitive data and masking
- Secrets Manager vs Parameter Store
- Secrets Manager cheat sheet
Further reading
- Rotate Secrets Manager secrets
- Rotation by Lambda function
- Secrets Manager quotas
- Secret encryption and decryption in Secrets Manager
- Replicate secrets across Regions
- Referencing Secrets Manager secrets from Parameter Store
- Lambda function rotation strategies
- Access Secrets Manager secrets from a different account
- AWS Systems Manager Parameter Store
AWS Backup, DLM and DataSync
Centralized backup plans and vaults, EBS snapshot lifecycle automation, and encrypted data transfer, with ransomware-resilient patterns.
Finding and masking sensitive data
Finding sensitive data in S3 with Macie, masking it in CloudWatch Logs, the status of SNS message data protection and S3 Object Lambda, and choosing between masking, redaction, tokenization and encryption.