Sub topic 2
Parameter Store basics: names, paths and hierarchies
This chapter assumes you can run AWS CLI commands, read JSON output, and read short Python scripts that use boto3. It also assumes you know what an IAM role and an AWS Region are. Parameter types, tiers, encryption and IAM policies each get their own chapter. Here the focus is how parameters are named and organized, because those names drive access control, retrieval and environment separation later.
What a parameter is
AWS Systems Manager Parameter Store is a key-value store for configuration data. Each entry is a parameter with a name, a value, a type and a version number. Parameters live in one account and one Region. A parameter named /myapp/prod/db/host in us-east-1 is a different object from one with the same name in eu-west-1.
Parameter Store is the right place for values such as hostnames, feature flags, timeouts and AMI IDs. It can also hold encrypted values, which later chapters cover.
Names and the rules behind them
A parameter name is a string. Name rules are a common source of errors, so learn these:
- Names are case-sensitive.
/myapp/Prod/dband/myapp/prod/dbare different parameters. - Allowed characters are letters, numbers, and
.-_/. Spaces and other symbols are rejected. - A name cannot be changed after creation. To rename, create a new parameter and delete the old one.
- A name cannot start with
awsorssm(case-insensitive) at its first level. Those prefixes are reserved for AWS-provided parameters. - A hierarchy can be at most 15 levels deep, and the full name, including the path, has a length limit (1,011 characters).
A name without slashes, such as db-host, is a flat name. A name with slashes, such as /myapp/prod/db/host, is a hierarchical name. Prefer hierarchical names. Flat names cannot be fetched together by path, and you cannot write IAM policies that cover a group of them with a single prefix.
Paths and hierarchies
In a hierarchical name, each / separates a level. Everything before the last / is the path. The final segment is the parameter's own name. Parameter Store has no folder objects. A path exists only because parameters share a prefix, so you never create or delete a path.
A widely used convention is /application/environment/component/setting:
This layout pays off in three ways:
- One call loads a whole environment. You fetch
/myapp/prodand get every setting beneath it. - One IAM statement covers one environment. A resource such as
parameter/myapp/prod/*grants access to production settings and nothing else. - Environments differ by one path segment. The same code runs in dev and prod and only the prefix changes, usually through a single environment variable.
Put the most stable, broadest qualifier first. Because IAM wildcards match prefixes, /myapp/prod/... can be granted to a production role in one line. If you put the environment last (/myapp/db/host/prod), you lose that.
Creating parameters
The next commands create two parameters under a shared path. The first is a plain String. The second is a SecureString, which is encrypted with the AWS managed key alias/aws/ssm unless you specify another key.
aws ssm put-parameter \
--name /myapp/prod/db/host \
--value db.example.internal \
--type String
aws ssm put-parameter \
--name /myapp/prod/db/password \
--value 'REPLACE_ME' \
--type SecureStringRunning put-parameter again with an existing name fails with ParameterAlreadyExists. To change the value, add --overwrite:
aws ssm put-parameter \
--name /myapp/prod/db/host \
--value db2.example.internal \
--type String \
--overwriteEvery successful write creates a new version, starting at 1. The current version is returned by default. To read an older one, append a selector to the name, as in /myapp/prod/db/host:1. Overwriting does not change the type of an existing parameter in a way the API will accept silently. Changing a String to a SecureString, for example, is an error you should expect, so create a new parameter if the type must change.
Reading one parameter and a whole path
Reading a single parameter by exact name uses get-parameter. You must pass --with-decryption to see a SecureString in plain text. Without it you get ciphertext.
To load many values at once, use get-parameters-by-path:
aws ssm get-parameters-by-path \
--path /myapp/prod \
--recursive \
--with-decryptionThree behaviors catch people out:
- Recursion is off by default. Without
--recursive, you get only parameters directly under/myapp/prod, such as/myapp/prod/timeout. Parameters under/myapp/prod/db/are skipped. - Pages are small. Each response holds at most 10 parameters. The CLI paginates for you, but with an SDK you must follow
NextTokenor use a paginator. A loader that reads only the first page silently drops configuration. - Paths do not include the trailing slash. Pass
/myapp/prod, not/myapp/prod/.
Here is a loader that reads a path with a boto3 paginator and turns names into environment-style keys. It prints only the keys, not the values.
import boto3
ssm = boto3.client("ssm")
def load_config(path: str) -> dict:
prefix = path.rstrip("/") + "/"
config = {}
paginator = ssm.get_paginator("get_parameters_by_path")
for page in paginator.paginate(Path=path, Recursive=True, WithDecryption=True):
for param in page["Parameters"]:
key = param["Name"][len(prefix):].replace("/", "_").upper()
config[key] = param["Value"]
return config
if __name__ == "__main__":
settings = load_config("/myapp/prod")
print(sorted(settings)) # e.g. ['DB_HOST', 'DB_PASSWORD']The /myapp/prod/db/host parameter becomes DB_HOST. Because the function strips the prefix, the same code works for /myapp/dev without changes.
Finding and listing parameters
get-parameters-by-path returns values. To list names and metadata without reading values, use describe-parameters. It never returns the value, and it needs a different IAM permission, ssm:DescribeParameters. That permission cannot be limited by parameter path, so treat it as an account-wide listing of names.
aws ssm describe-parameters \
--parameter-filters "Key=Path,Option=Recursive,Values=/myapp/prod" \
--query "Parameters[].[Name,Type,Version]" \
--output tableUse this to audit what exists under a path, check types, or find parameters that have never been updated.
Naming conventions that last
- Use lowercase and hyphens or underscores consistently. Case sensitivity means mixed styles produce near-duplicate names.
- Decide the environment segment early. Renaming means recreating parameters and updating every reader.
- Group by consumer, not by value type.
/myapp/prod/db/hostand/myapp/prod/db/passwordsit together even though one is aStringand the other aSecureString. - Keep shared values in their own top-level path, such as
/shared/prod/vpc/id, so one application's policy can grant it separately. - Do not encode secrets or sensitive details in the name itself. Names appear in CloudTrail logs and in
describe-parametersoutput, and anyone with listing permission can read them.
Common errors
| Error or symptom | Likely cause | Fix |
|---|---|---|
| `ParameterNotFound` | Wrong Region, missing leading slash, or case mismatch | Check `--region` and use the exact name, including the leading `/` |
| `ParameterAlreadyExists` | `put-parameter` on an existing name | Add `--overwrite` |
| `ValidationException` on the name | Illegal characters, or a name starting with `aws` or `ssm` | Use only letters, digits, `. - _ /` and a different first segment |
| Path query returns fewer parameters than expected | Missing `--recursive`, or only the first page was read | Add `--recursive` and paginate |
| `AccessDeniedException` on a path read | The policy covers `parameter/myapp/prod/*` for the wrong action, or lacks `kms:Decrypt` for SecureStrings | Allow `ssm:GetParametersByPath` and the key permission |
| Value looks like random text | Read without `--with-decryption` | Pass `--with-decryption` |
Exercise
A service role is allowed ssm:GetParametersByPath on parameter/myapp/prod/*. Your loader calls get_parameters_by_path(Path="/myapp/prod") and the result lacks /myapp/prod/db/host, although the parameter exists and the call succeeds. What is wrong, and what is the fix?
Show answer
The call is missing Recursive=True, so it returns only parameters directly under /myapp/prod, not those in the db sub-path. Add Recursive=True, and use a paginator or follow NextToken because each page holds at most 10 parameters.
Exercise
Why is /myapp/prod/db/host a better name than /myapp/db/host/prod for access control?
Show answer
IAM resource wildcards match prefixes. With the environment early in the path, one statement on parameter/myapp/prod/* grants a production role everything in that environment. With the environment at the end, no single prefix selects it, so you would need to list parameters individually.