Sub topic 2
Parameter Store basics: names, paths and hierarchies
This chapter assumes you can use the AWS CLI, read JSON, and understand IAM roles. Parameter Store is a capability of AWS Systems Manager. It stores configuration values as named parameters. Good names make the rest of your setup easier, because IAM policies and bulk reads both work on name prefixes.
What a parameter is
A parameter is a named value. Each one has a name, a type, a value and a version number. Every time you overwrite a parameter, its version increases by one. This chapter covers names and paths. The next chapter covers types and tiers.
Hierarchical names
A parameter name can be a simple string such as db-host. A better choice is a path, which is a name made of segments separated by forward slashes. The path always starts with a slash.
/myapp/prod/db/host
/myapp/prod/db/password
/myapp/staging/db/hostHere myapp is the application, prod is the environment, and db/host is the setting. The hierarchy has no special meaning to AWS. It is a naming convention, and the slashes let you group parameters by prefix.
Creating parameters
Use put-parameter to create a parameter. This example creates a plain String and a SecureString under the same path. A SecureString is encrypted with the AWS managed key alias/aws/ssm unless you choose 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 SecureStringIf the name already exists, the call fails. To change a value, add --overwrite. That creates a new version of the parameter.
Reading a whole path
A shared path lets you load an entire environment in one call. get-parameters-by-path returns every parameter under a prefix. The --recursive flag includes deeper levels. The --with-decryption flag returns SecureString values as plaintext.
aws ssm get-parameters-by-path \
--path /myapp/prod \
--recursive \
--with-decryptionWithout --recursive, the call returns only parameters directly under /myapp/prod. It would skip /myapp/prod/db/host, which sits two levels deeper. This is a common source of "missing" parameters.
Each call returns a limited number of results per page. The AWS CLI follows the pages for you. In an SDK, use a paginator or check for a NextToken in the response.
Naming rules and gotchas
- A name can contain letters, numbers and the characters
.,-,_and/. - Names are case-sensitive, so
/MyApp/prodand/myapp/prodare different parameters. - A hierarchy can have at most 15 levels.
- Names cannot start with
awsorssm, in any letter case. These prefixes are reserved. - After you create a parameter, you cannot rename it. You must create a new one and delete the old one.
Why the design matters
A path convention gives you three things:
- Bulk loading. One
get-parameters-by-pathcall fetches an environment's settings. - Scoped permissions. IAM resource ARNs can end in a wildcard, so one statement covers a whole prefix.
- Clear ownership. Anyone reading
/myapp/prod/db/hostknows what it is for.
Pick the convention before you create many parameters. Because names cannot change, a poor layout means recreating them later.
Exercise
You run aws ssm get-parameters-by-path --path /myapp/prod and it does not return /myapp/prod/db/host. Why, and what fixes it?
Show answer
Without --recursive, the call returns only parameters directly under the path, not those in deeper levels such as /myapp/prod/db/. Adding --recursive returns them.
Exercise
A teammate wants to rename /myapp/prod/db/hostname to /myapp/prod/db/host. How is this done?
Show answer
Parameter names cannot be changed. Create a new parameter named /myapp/prod/db/host with the same value and type, update the applications that read it, then delete the old parameter.