Using paths to create hierarchies in Parameter Store

Parameter Store only supports a limited number of character for the parameter
name. As per the error message you’re presented with, Only a mix of letters,
numbers and the following 3 symbols .-_ are allowed.

What that error fails to mention is that you can actually use a fourth symbol,
the forward slash, /.

That particular special character also unlocks some additional functionality
within AWS Parameter Store. When you utilize the / character, you are creating
a path, similar to paths on a Linux or Unix-based operating system.

This allows you to do things like group parameters for different environments,
or whatever sort of hierarchy you’d like to impose on your Parameter Store
parameters:

/Dev/External/StripeAPIKey
/Staging/Data_Stores/Redis_Elasticache/Host
/Prod/Whatever/You/Want/To/Call/It

When you use the / you can still fetch the parameters with getParameter and
getParameters but the real magic happens when you use getParametersByPath.

When getting parameters by their path, you can get all of the parameters at the
depth of the path of your choosing:

import * as AWS from 'aws-sdk'

const ssm = new AWS.SSM

const staging = await ssm.getParametersByPath({
	Path: '/Staging/',
	WithDecryption: true,
}).promise

const stagingDataStores = await ssm.getParametersByPath({
	Path: '/Staging/Data_Stores/',
	WithDecryption: true,
}).promise

const stagingDataStoreRedis = await ssm.getParametersByPath({
	Path: '/Staging/Data_Store/Redis_Elasticache',
	WithDecryption: true,
}).promise
Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.