Using paths to create hierarchies in Parameter Store by Josh Sherman

0
20

Parameter Store only supports a limited number of characters for the parameter name. As per the error message you are 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 it 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();

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here