Secrets Manager and Parameter Store
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Operations and security
-
Phase 3: SQL Server on AWS
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Database passwords in config files, API keys in user data, connection strings in Git: that’s how secrets leak. Picking between Secrets Manager vs Parameter Store comes down to where each kind of value belongs, and to having servers read those values at runtime with their role so they never carry them around.
You’ll put some settings and a SecureString in Parameter Store, create a database secret in Secrets Manager and give it a new version, and then have a private server read both using its instance role. After that you’ll fix the two mistakes that make an app show gibberish or AccessDenied on its first deploy.
| Time | You need | By the end you can |
|---|---|---|
| 50 minutes (one small instance and four interface endpoints for under an hour) | Lesson 30 done, saat-vpc, Start-SsmEndpoints.ps1 and Stop-SsmEndpoints.ps1, saat-ec2-ssm-profile, your laptop signed in as saat-admin. Cost: about USD 0.10 (endpoints, the instance, and one secret for an hour). | Store String, StringList and SecureString parameters, create a Secrets Manager secret and version it, give a server least-privilege read access, and sort out decryption and ARN-suffix permission problems. |
What it is, in one line
Parameter Store holds configuration values, plus simple secrets as SecureString, while Secrets Manager holds the secrets that need rotation, versions and tight control.
In Simple Words
The notice board and the safe
Most offices have a notice board with the Wi-Fi name, the canteen timings and the meeting room numbers on it, and anyone in the office can read it, which is Parameter Store with plain String values. The same office has a safe for the cash and the master key, and only certain people can open it; the code changes every month and the old one keeps working for a day while everyone catches up, and that’s Secrets Manager. You could lock a page in a drawer under the notice board (a SecureString), and for a lot of small offices that’s enough, but that drawer won’t change its own code every month.
Engineer's View
What each service really offers
Parameter Store, which is part of Systems Manager, stores values under hierarchical names like /saat/app/db_host as String, StringList or SecureString (encrypted with KMS, using aws/ssm by default). Standard parameters go up to 4 KB and cost nothing to store, while Advanced parameters allow 8 KB and policies such as expiry, and you pay per parameter. It keeps version history and labels, and one call can read a whole path.
Secrets Manager stores secrets up to 64 KB, often as JSON with username, password, host and port, encrypts them with KMS, and keeps versions with staging labels: AWSCURRENT, AWSPREVIOUS, and AWSPENDING while a rotation is running. Rotation runs on a schedule, either through a Lambda function or as managed rotation for RDS and some other services, and you can replicate secrets to other Regions.
Every secret ARN ends with a random six-character suffix, and that matters when you write IAM policies.
Both are read at runtime through IAM, so the instance or task role needs ssm:GetParameter or secretsmanager:GetSecretValue on specific names, and KMS decrypt as well if it’s a customer managed key. Parameter Store can also hand back a secret through /aws/reference/secretsmanager/. From private subnets you need the ssm or secretsmanager endpoints.
How it works, step by step
This is how you decide where a value goes:
1Settings go to Parameter Store
Hostnames, feature flags, AMI IDs and bucket names, meaning values that aren’t secret, or low-risk secrets that never rotate.
2Credentials go to Secrets Manager
Database passwords, API keys, and anything an auditor is going to ask “when was this last rotated?” about.
3Apps read them at startup
Nothing gets baked into the AMI, the code or the user data, and the app reads the values with its role:
When the secret changes, you don’t redeploy anything, because the next read picks up the new AWSCURRENT version. A lot of SDKs and the Secrets Manager agent cache values for a few minutes to keep API calls and cost down.
✅ Checkpoint: You can say which values go in which service, what AWSCURRENT and AWSPREVIOUS mean, and what a server needs before it can read a secret.
Hands-on lab: Secrets Manager vs Parameter Store on a real server
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Sign in and set up:
cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$v = Get-Content C:\aws-lab\saat-vpc.json | ConvertFrom-Json
$acct = aws sts get-caller-identity --query Account --output text1Store settings in Parameter Store
Paste this whole block:
aws ssm put-parameter --name /saat/app/db_host --type String --value saat-db.internal --tags Key=course,Value=saatvedha-aws | Out-Null
aws ssm put-parameter --name /saat/app/features --type StringList --value 'orders,reports' --tags Key=course,Value=saatvedha-aws | Out-Null
aws ssm put-parameter --name /saat/app/db_password --type SecureString --value 'Lab-Only-Pass-91' --tags Key=course,Value=saatvedha-aws | Out-Null
aws ssm get-parameters-by-path --path /saat/app --recursive --with-decryption --query "Parameters[].[Name,Type,Value]" --output textYou should see this:
/saat/app/db_host String saat-db.internal
/saat/app/db_password SecureString Lab-Only-Pass-91
/saat/app/features StringList orders,reportsA single call reads everything under /saat/app, and if you give each app and environment its own path (/prod/orders/, /test/orders/) the permissions stay simple.
2Create a secret and give it a new version
Paste this whole block:
$pw = aws secretsmanager get-random-password --password-length 24 --exclude-punctuation --query RandomPassword --output text
[ordered]@{ username = 'appuser'; password = $pw; host = 'saat-db.internal'; port = 1433 } | ConvertTo-Json -Compress | Set-Content secret.json
$secretArn = aws secretsmanager create-secret --name saat/app/db --description "lesson 31 app database login" --secret-string file://secret.json --tags Key=course,Value=saatvedha-aws --query ARN --output text
$secretArn
$pw2 = aws secretsmanager get-random-password --password-length 24 --exclude-punctuation --query RandomPassword --output text
[ordered]@{ username = 'appuser'; password = $pw2; host = 'saat-db.internal'; port = 1433 } | ConvertTo-Json -Compress | Set-Content secret.json
aws secretsmanager put-secret-value --secret-id saat/app/db --secret-string file://secret.json | Out-Null
Remove-Item secret.json
aws secretsmanager list-secret-version-ids --secret-id saat/app/db --query "Versions[].VersionStages" --output textYou should see something like this:
arn:aws:secretsmanager:ap-south-1:111122223333:secret:saat/app/db-AbCdEf
AWSCURRENT
AWSPREVIOUSSee the -AbCdEf on the end of the ARN? It comes back in the break lab. The old password is still there as AWSPREVIOUS, and that’s what lets rotation happen without breaking apps that haven’t re-read the secret yet. Real rotation runs on a schedule, and you’ll see managed rotation for RDS in Lesson 44.
3Give a server read access
Paste the whole block. It adds a scoped policy to the instance role, plus the Secrets Manager endpoint and app01:
@'
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Action": [ "ssm:GetParameter", "ssm:GetParameters", "ssm:GetParametersByPath" ], "Resource": "arn:aws:ssm:ap-south-1:ACCT:parameter/saat/app/*" },
{ "Effect": "Allow", "Action": "secretsmanager:GetSecretValue", "Resource": "arn:aws:secretsmanager:ap-south-1:ACCT:secret:SECRET_RESOURCE" }
]
}
'@ -replace 'ACCT', $acct -replace 'SECRET_RESOURCE', 'saat/app/*' | Set-Content read-app-config.json
aws iam put-role-policy --role-name saat-ec2-ssm-role --policy-name read-saat-app-config --policy-document file://read-app-config.json
.\Start-SsmEndpoints.ps1
$smEp = aws ec2 create-vpc-endpoint --vpc-id $v.VpcId --vpc-endpoint-type Interface --service-name com.amazonaws.ap-south-1.secretsmanager --subnet-ids $v.PrivateA --security-group-ids $v.EndpointSg --private-dns-enabled --tag-specifications 'ResourceType=vpc-endpoint,Tags=[{Key=Name,Value=saat-secretsmanager-ep},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=31}]' --query VpcEndpoint.VpcEndpointId --output text
$base = aws ssm get-parameter --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --query Parameter.Value --output text
$i = aws ec2 run-instances --image-id $base --instance-type t3.micro --subnet-id $v.PrivateA --security-group-ids $v.AppSg --iam-instance-profile Name=saat-ec2-ssm-profile --metadata-options HttpTokens=required --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=app01},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=31}]' --query "Instances[0].InstanceId" --output text
do { Start-Sleep 20; $p = aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$i" --query "InstanceInformationList[0].PingStatus" --output text } until ($p -eq 'Online')
do { Start-Sleep 10; $s = aws ec2 describe-vpc-endpoints --vpc-endpoint-ids $smEp --query "VpcEndpoints[0].State" --output text } until ($s -eq 'available')
"$p $s"You should see this:
Online available
4Read both values from the server
Paste this whole block:
'{ "commands": [ "aws ssm get-parameter --name /saat/app/db_host --query Parameter.Value --output text --region ap-south-1", "aws secretsmanager get-secret-value --secret-id saat/app/db --query SecretString --output text --region ap-south-1" ] }' | Set-Content read-params.json
$cmd = aws ssm send-command --document-name AWS-RunShellScript --instance-ids $i --parameters file://read-params.json --query Command.CommandId --output text
Start-Sleep 15
aws ssm get-command-invocation --command-id $cmd --instance-id $i --query StandardOutputContent --output textYou should see something like this:
saat-db.internal
{"username":"appuser","password":"V8qt2LmZ0pRw4sXc7nBd1KfH","host":"saat-db.internal","port":1433}The server never had a password in its image, its user data or its files, because it asked for it with its role. Printing a secret into command output is only OK in this lab, since Run Command keeps output in its history, and real apps read secrets in code and never log them.
✅ Checkpoint: There are three parameters under /saat/app, saat/app/db has AWSCURRENT and AWSPREVIOUS versions, and app01 read both the host and the secret using its instance role. Keep it all for the break lab.
Break It, Then Fix It
These two mistakes tend to show up on an app’s very first deploy.
1Break it: read a SecureString without decryption
Ask for the password the way a lot of scripts do:
aws ssm get-parameter --name /saat/app/db_password --query Parameter.Value --output textYou should see something like this:
AQICAHhW5gQ9mT2rL0xY7pVnB3kZ8cE1sJ4uD6fR2aN0qO9iUwF3AAAAajBoBgkqhkiG9w0BBwagWzBZAgEA...There’s no error, you only get the encrypted value back. The app then tries to log in to the database with that string and fails with “login failed for user”, which sends people off checking the database when the problem is in the code. Fix: ask for decryption explicitly:
aws ssm get-parameter --name /saat/app/db_password --with-decryption --query Parameter.Value --output textYou should see this:
Lab-Only-Pass-912Break it: a policy that names the secret exactly
Narrow the server’s policy down to the exact secret name and read again:
(Get-Content read-app-config.json -Raw) -replace 'secret:saat/app/\*', 'secret:saat/app/db' | Set-Content read-app-config.json
aws iam put-role-policy --role-name saat-ec2-ssm-role --policy-name read-saat-app-config --policy-document file://read-app-config.json
Start-Sleep 15
$cmd = aws ssm send-command --document-name AWS-RunShellScript --instance-ids $i --parameters file://read-params.json --query Command.CommandId --output text
Start-Sleep 15
aws ssm get-command-invocation --command-id $cmd --instance-id $i --query StandardErrorContent --output textYou’ll get an error like this:
An error occurred (AccessDeniedException) when calling the GetSecretValue operation: User: arn:aws:sts::111122223333:assumed-role/saat-ec2-ssm-role/i-0d1e2f3a4b5c60071 is not authorized to perform: secretsmanager:GetSecretValue on resource: saat/app/db because no identity-based policy allows the secretsmanager:GetSecretValue action
The policy says secret:saat/app/db, but the real ARN is secret:saat/app/db-AbCdEf, and since they don’t match, nothing allows the call. Fix: match the six-character suffix with question marks, which is tighter than using a star:
(Get-Content read-app-config.json -Raw) -replace 'secret:saat/app/db"', 'secret:saat/app/db-??????"' | Set-Content read-app-config.json
aws iam put-role-policy --role-name saat-ec2-ssm-role --policy-name read-saat-app-config --policy-document file://read-app-config.json
Start-Sleep 15
$cmd = aws ssm send-command --document-name AWS-RunShellScript --instance-ids $i --parameters file://read-params.json --query Command.CommandId --output text
Start-Sleep 15
aws ssm get-command-invocation --command-id $cmd --instance-id $i --query "[Status,ResponseCode]" --output textYou should see this:
Success 0Now clean up. A deleted secret hangs around for 7 to 30 days before it’s really gone, and you can’t reuse its name until then:
aws ssm delete-parameters --names /saat/app/db_host /saat/app/features /saat/app/db_password | Out-Null
aws secretsmanager delete-secret --secret-id saat/app/db --recovery-window-in-days 7 --query DeletionDate --output text
aws iam delete-role-policy --role-name saat-ec2-ssm-role --policy-name read-saat-app-config
aws ec2 terminate-instances --instance-ids $i | Out-Null
aws ec2 delete-vpc-endpoints --vpc-endpoint-ids $smEp | Out-Null
aws ec2 wait instance-terminated --instance-ids $i
.\Stop-SsmEndpoints.ps1
Remove-Item read-app-config.json, read-params.json
.\Find-LabResources.ps1✅ Checkpoint: You fixed an encrypted value that came back because --with-decryption was missing, and an AccessDenied caused by the secret ARN suffix. The parameters, instance policy, app01 and endpoints are gone, and the secret is scheduled for deletion.
This happened at work
The password that lived in a public repo
An e-commerce startup kept its database password in appsettings.json so new developers could “just run it”. One day a contractor pushed a copy of the repository to a public GitHub account to show a friend, and within hours automated scanners had picked it up. The database itself was in a private subnet, so nobody could connect to it directly, but the same password had been reused for an internet-facing admin portal, and the attackers logged in there and exported customer emails before anyone noticed. Afterwards they moved every credential into Secrets Manager with 30-day rotation, gave each service its own secret and role, turned on secret scanning for all repositories, and made it a rule that a password used in two places counts as a finding by itself.
Common mistakes and troubleshooting
| Mistake | What happens | What to do |
|---|---|---|
Reading SecureString without --with-decryption | App gets ciphertext and fails to log in | Always request decryption |
| IAM resource with the exact secret name | AccessDenied: the ARN has a -XXXXXX suffix | Use name-?????? or a path wildcard |
| Secrets in user data, AMIs or Git | Anyone with access to those sees them | Read at runtime with a role |
| Printing secrets in logs or command output | Secrets stored in log history | Never log secret values |
| Deleting and recreating a secret with the same name | Name blocked during the recovery window | Restore it, or wait; plan names carefully |
| Using Secrets Manager for every setting | Extra cost for non-secret values | Settings in Parameter Store, credentials in Secrets Manager |
Interview questions
Click a question to open it. Each one is phrased the way an interviewer would ask it, and under it you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. A developer asks whether to store something in Parameter Store or Secrets Manager. How would you help them decide?
Why they ask this: They want to know you’d pick the right service, because the wrong one either costs more or leaves secrets with no rotation.
How you might answer: I’d ask what the value is. If it’s configuration that doesn’t rotate, like hostnames, feature flags or IDs, I’d put it in Parameter Store, where standard parameters cost nothing to store. If it’s a credential that needs rotation and versioning, like a database password, it goes in Secrets Manager.
2. Can you explain in simple words what a SecureString parameter is?
Why they ask this: They’re checking you know how to keep sensitive values in Parameter Store, and that you know KMS permissions come into it.
How you might answer: It’s a Parameter Store value that’s encrypted with KMS, and to read the real value I use --with-decryption. The caller also needs permission on the KMS key, which by default is aws/ssm.
3. Your app on EC2 needs a database password. Where should it get it from, and how?
Why they ask this: Passwords sitting in code or config files are one of the most common causes of leaks, so they want to see good security habits.
How you might answer: The app should read it from Secrets Manager at startup using the instance role, and the role’s policy should allow GetSecretValue on that one secret only. I’d never put the password in a file on the server or in the code.
2–5 years experience
4. You see AWSCURRENT and AWSPREVIOUS labels on a secret. What do they mean, and why do they matter?
Why they ask this: They want to know you understand secret versioning, since that’s how rotation can happen without breaking running apps.
How you might answer: They’re staging labels on the secret’s versions. AWSCURRENT is what apps get by default, and AWSPREVIOUS is the version just before it, kept so clients don’t break halfway through a rotation. While a rotation is running there’s also an AWSPENDING version, which is the new value being tested.
5. An app gets AccessDenied reading a secret, but the IAM policy looks right. What would you check?
Why they ask this: Several small things can block access to a secret even when the policy looks fine, so they want a careful troubleshooting order.
How you might answer: I’d look at the Resource ARN in the policy first, because it often leaves out the six-character suffix Secrets Manager adds. Then I’d check whether the secret uses a customer managed KMS key the role can’t decrypt, or whether a resource policy on the secret denies it, and if the app is in a private subnet, that it has the endpoint and is calling the right Region.
6. Walk me through what happens when Secrets Manager rotates a database password.
Why they ask this: They want to see you understand rotation step by step, which helps when a rotation fails and you need to know where it stopped.
How you might answer: A Lambda function, or managed rotation, creates a new version of the secret labelled AWSPENDING, sets that new password on the database, tests it, and then moves the AWSCURRENT label across to it. Apps pick up the new value when they re-read the secret, so I make sure our apps don’t cache it forever.
Senior level
7. Say you join a team with 60 microservices and secrets scattered everywhere. How would you design secrets management for them?
Why they ask this: They’re looking for platform thinking (naming, access, rotation, recovery and detection) and whether you can keep secrets safe at scale.
How you might answer: I’d give each service and environment its own secret, named by path, with KMS keys per environment. Access would use resource-based policies along with role policies, and each type of secret would get a rotation schedule. Apps would use caching clients or the Secrets Manager agent, with cross-Region replicas for DR, and I’d add secret scanning in CI and alerts on GetSecretValue from principals we don’t expect.
8. A database password just leaked. What do you do in the first hour?
Why they ask this: They want a quick, ordered incident response where you stop the damage, find the cause and make sure it doesn’t happen again.
How you might answer: I’d rotate the secret straight away, along with anywhere else the same password was reused, then check the database logs and CloudTrail for any use of it and revoke open sessions. After that I’d work out how it leaked, whether through a repo, a log or a ticket, remove it from there, and add scanning and tighter read permissions so it doesn’t happen again.
Quick quiz
Q1. Where should a feature flag usually live?
- Secrets Manager
- Parameter Store
- User data
- The AMI
Show answer
B — Non-secret settings belong in Parameter Store.
Q2. What did get-parameter return without --with-decryption?
- An error
- The encrypted value
- An empty string
- The previous version
Show answer
B — SecureString values stay encrypted unless you ask.
Q3. Why did the exact-name policy fail?
- The secret was deleted
- Secret ARNs end with a random suffix
- The KMS key was disabled
- The endpoint was down
Show answer
B — Use saat/app/db-?????? to match the suffix.
Q4. Which label do apps receive by default?
- AWSPREVIOUS
- AWSPENDING
- AWSCURRENT
- LATEST
Show answer
C — GetSecretValue returns AWSCURRENT unless asked otherwise.
Q5. What do private servers need to reach Secrets Manager without NAT?
- A public IP
- The secretsmanager interface endpoint
- Port 22
- An S3 bucket
Show answer
B — Interface endpoints keep calls inside the VPC.
Quick recap
- Use Parameter Store for settings and Secrets Manager for credentials that rotate.
- Read values at runtime with the instance or task role, and never from files or code.
- SecureString needs
--with-decryption. - Secret ARNs end with a six-character suffix, so match it in your policies.
- AWSCURRENT and AWSPREVIOUS are what let rotation happen without breaking apps.
Next lesson
Lesson 32: GuardDuty and Security Hub → Next you’ll switch on GuardDuty, generate some sample findings, send them to saat-alerts, and see how Security Hub scores your account.
Further reading: Secrets Manager vs Parameter Store
Want to go deeper into Secrets Manager vs Parameter Store? Read What is AWS Secrets Manager? and AWS Systems Manager Parameter Store. You can also see the full plan for this course on the AWS Cloud Administration course page.
