ssm-parameter-bridge
v0.2.4
Published
Small helpers for reading and writing AWS Systems Manager (SSM) Parameter Store parameters in AWS CDK v2, with a consistent tagging convention.
Readme
ssm-parameter-bridge
Small helpers for reading and writing AWS Systems Manager (SSM) Parameter Store parameters in AWS CDK v2, with a consistent tagging convention. The public API uses readFrom*Parameter / writeTo*Parameter naming.
Features
- Read SSM
Stringparameters withreadFromStringParameter(CloudFormation dynamic references; return value may be a CDK token) - Read SSM
StringListparameters withreadFromStringListParameter(return value may include CDK tokens) - Optionally validate Parameter Store value types at deploy time via
ssm.ParameterValueType - Create
String/StringListparameters withwriteToStringParameter/writeToStringListParameter - Apply a default
ssm:managed-by=ssm-parameter-bridgetag on created parameters, plus optional custom tags - Expand a
StringListtoken into a fixed-length CloudFormationstring[]withsplitListTokenToStrings
Installation
Using npm:
npm install ssm-parameter-bridgeUsing yarn:
yarn add ssm-parameter-bridgeUsage
import * as ssm from 'aws-cdk-lib/aws-ssm';
import { Stack } from 'aws-cdk-lib';
import {
readFromStringListParameter,
readFromStringParameter,
splitListTokenToStrings,
writeToStringListParameter,
writeToStringParameter,
} from 'ssm-parameter-bridge';
const stack = new Stack();
// Read a String parameter (optionally typed)
const imageId = readFromStringParameter(stack, '/my/ami', ssm.ParameterValueType.AWS_EC2_IMAGE_ID);
// Read a StringList parameter (optionally typed). May contain a token.
const subnetsTokenList = readFromStringListParameter(stack, '/my/subnet-ids', ssm.ParameterValueType.STRING);
// If you need a fixed-length array at CloudFormation level:
const subnets = splitListTokenToStrings(subnetsTokenList, 3);
// Write parameters with default + custom tags
writeToStringParameter(stack, 'ParamString', {
parameterName: '/my/app/value',
stringValue: 'hello',
tags: { env: 'dev' },
});
writeToStringListParameter(stack, 'ParamList', {
parameterName: '/my/app/list',
stringListValue: ['a', 'b'],
tags: { team: 'platform' },
});Options
readFromStringParameter(scope, parameterName, type?)
scope: construct scope used to bind the lookup tokenparameterName: parameter name (for example,/my/app/value)type(optional):ssm.ParameterValueTypeto validate at deploy time- returns: a
stringthat may be a CDK token
readFromStringListParameter(scope, parameterName, type?)
scope: construct scope used to bind the lookup tokenparameterName: parameter name (for example,/my/app/list)type(optional):ssm.ParameterValueTypeto validate at deploy time- returns: a
string[]that may contain CDK tokens
writeToStringParameter(scope, id, props)
scope: construct scope to define the parameter inid: CDK construct id for the parameter resourceprops.parameterName(required): parameter name (for example,/my/app/value)props.stringValue(required): parameter valueprops.description(optional): parameter descriptionprops.tier(optional): SSM parameter tier (defaults toSTANDARD)props.tags(optional): additional tags to apply (in addition tossm:managed-by)
writeToStringListParameter(scope, id, props)
scope: construct scope to define the parameter inid: CDK construct id for the parameter resourceprops.parameterName(required): parameter name (for example,/my/app/list)props.stringListValue(required): list of stringsprops.description(optional): parameter descriptionprops.tags(optional): additional tags to apply (in addition tossm:managed-by)
splitListTokenToStrings(listToken, length)
listToken: token list produced by an SSM StringList lookuplength(required): fixed output length; must be an integer (>= 0) and known at synth time- returns: a CloudFormation-level fixed-length
string[]
Requirements
- Node.js >= 20
aws-cdk-lib^2.232.0constructs^10.5.1
License
This project is licensed under the (Apache-2.0) License.
