Sub topic 13
Reading Secrets Manager secrets through Parameter Store
This chapter assumes you know how to create parameters and secrets, and that you have read the earlier chapters on IAM policies and KMS encryption. You should be comfortable with the AWS CLI and boto3.
The idea
Parameter Store and Secrets Manager are separate services with separate APIs. AWS also lets you read a Secrets Manager secret through the Parameter Store API. You call GetParameter with a name that starts with the reserved prefix /aws/reference/secretsmanager/, followed by the secret's name.
This is not a copy of the secret. Parameter Store acts as a pass-through, and the value always comes from Secrets Manager. No parameter is created, so there is nothing to keep in sync.
The feature is useful in three situations:
- Your code or tooling already reads everything through the SSM API and you want one call path for both services.
- You want to start with Parameter Store and move a value to Secrets Manager later without changing the call.
- A tool supports SSM parameter references but has no Secrets Manager integration.
The request path
Reading a secret from the CLI
Earlier you created the secret myapp/prod/db. Read it through Parameter Store like this:
aws ssm get-parameter \
--name /aws/reference/secretsmanager/myapp/prod/db \
--with-decryptionThe name is the prefix plus the secret name exactly as Secrets Manager stores it. The secret name has no leading slash, so the full parameter name is /aws/reference/secretsmanager/myapp/prod/db.
The response has the same shape as any other GetParameter response. Parameter.Value holds the secret string. For the JSON secret from earlier, that is the whole JSON document as a string. Parameter Store does not extract individual keys, so you still parse the JSON yourself.
To print only the value, use the CLI's --query option:
aws ssm get-parameter \
--name /aws/reference/secretsmanager/myapp/prod/db \
--with-decryption \
--query Parameter.Value \
--output textReading a secret from boto3
The code is the same as for a normal parameter. Only the name differs.
import json
import boto3
ssm = boto3.client("ssm")
response = ssm.get_parameter(
Name="/aws/reference/secretsmanager/myapp/prod/db",
WithDecryption=True,
)
creds = json.loads(response["Parameter"]["Value"])
print(creds["username"])Print only non-sensitive fields such as the username. Never log the password or the full response.
Rules and restrictions
The reference path behaves like a read-only view of Secrets Manager. These are the behaviors to plan for:
| Behavior | What to expect |
|---|---|
| Decryption flag | `WithDecryption` must be true. Without it the call fails with a validation error, because the value is always treated as encrypted. |
| Writes | You cannot create or change a parameter under the reserved prefix. Change the secret through Secrets Manager. |
| Path queries | Do not rely on `GetParametersByPath` to list secrets. It does not enumerate Secrets Manager secrets, so call `GetParameter` or `GetParameters` with explicit names. |
| Region | The secret must be in the same Region as the SSM endpoint you call. |
| Value returned | You get the current version of the secret, the one labeled `AWSCURRENT`. |
| Metadata | Parameter Store metadata such as tiers and parameter policies does not apply, because the secret is not a parameter. |
Check the current AWS documentation for any additions to this list. Service behavior at the edges changes over time.
Permissions: two services are involved
A call through the reference path touches both services, so the caller needs permissions for both. Parameter Store checks that the caller may read the reference parameter. Secrets Manager checks that the caller may read the secret. If the secret uses a customer managed KMS key, the caller also needs access to that key.
Extend the application role's policy from the IAM chapter. This version allows only the reference path for one secret:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "ssm:GetParameter",
"Resource": "arn:aws:ssm:us-east-1:111122223333:parameter/aws/reference/secretsmanager/myapp/prod/db"
},
{
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "arn:aws:secretsmanager:us-east-1:111122223333:secret:myapp/prod/db-*"
},
{
"Effect": "Allow",
"Action": "kms:Decrypt",
"Resource": "arn:aws:kms:us-east-1:111122223333:key/EXAMPLE-KEY-ID"
}
]
}Note three details:
- The parameter ARN has no slash between
parameterand the name, because the name already starts with/. The result looks likeparameter/aws/reference/.... - The secret ARN ends in
-*to match the random suffix Secrets Manager adds. - The
ssm:GetParameterstatement is scoped to one secret's reference path. Avoidparameter/aws/reference/secretsmanager/*unless the role truly needs every secret.
A broad statement like parameter/myapp/prod/* from an earlier chapter does not cover this path. The reference prefix starts with /aws, not /myapp.
Troubleshooting
When a reference call fails, use the error message to find which layer denied it.
- A validation error that mentions decryption means you left out
--with-decryptionorWithDecryption=True. - An
AccessDeniedExceptionnamingssm:GetParametermeans the role lacks the reference-path statement. - An
AccessDeniedExceptionnamingsecretsmanager:GetSecretValuemeans the SSM statement is correct but the secret statement is missing or has the wrong ARN. Check the-*suffix and the Region. - An
AccessDeniedExceptionnamingkms:Decryptmeans the role cannot use the customer managed key. Check the key policy as well as the identity policy. - A
ParameterNotFounderror usually means a typo in the secret name or a call to the wrong Region.
To test a role without deploying, assume it and run the CLI command:
aws sts assume-role \
--role-arn arn:aws:iam::111122223333:role/myapp-prod-app \
--role-session-name ref-testExport the returned temporary credentials into your shell, then run the get-parameter command from earlier.
Caching and cost
Each reference call also reads the secret from Secrets Manager, so assume it carries the cost and rate limits of both services. The caching advice from the earlier chapter applies in full. Read the value once at startup or cache it for a short time, and do not call it on every request.
If you cache through a library, check that it supports the SSM API for your use. Many Secrets Manager caching libraries call only the Secrets Manager API. The reference path gives you no extra caching.
When to avoid it
Skip the reference path in these cases:
- You need a specific version or staging label. The reference path returns the current version, and the Secrets Manager API gives you explicit control over version stages.
- You need a single JSON key. The Secrets Manager API and dynamic references in CloudFormation can extract keys, but the reference path returns the whole string.
- You are writing new application code. Calling Secrets Manager directly removes one layer and one permission statement.
Exercise
A role has the policy ssm:GetParameter on arn:aws:ssm:us-east-1:111122223333:parameter/myapp/prod/* and secretsmanager:GetSecretValue on the secret myapp/prod/db-*. It calls aws ssm get-parameter --name /aws/reference/secretsmanager/myapp/prod/db --with-decryption and gets AccessDeniedException. What is missing, and what ARN would you add?
Show answer
The ssm:GetParameter statement does not cover the reference path, which starts with /aws/reference/secretsmanager/, not /myapp/prod/. Add ssm:GetParameter on arn:aws:ssm:us-east-1:111122223333:parameter/aws/reference/secretsmanager/myapp/prod/db. If the secret uses a customer managed KMS key, the role also needs kms:Decrypt on that key.
Exercise
Why does aws ssm get-parameters-by-path --path /aws/reference/secretsmanager --recursive not work as a way to list your secrets, and what should you do instead?
Show answer
The reference path is a pass-through for named secrets, not a parameter hierarchy, so path queries are not a reliable way to enumerate secrets. Call GetParameter or GetParameters with explicit secret names, or list secrets with aws secretsmanager list-secrets.