Skip navigation links

Package software.amazon.awscdk.services.ssm

AWS Systems Manager Construct Library

See: Description

Package software.amazon.awscdk.services.ssm Description

AWS Systems Manager Construct Library

---

cfn-resources: Stable

cdk-constructs: Stable


This module is part of the AWS Cloud Development Kit project.

Installation

Install the module:

 $ npm i @aws-cdk/aws-ssm
 

Import it into your code:

 // Example automatically generated. See https://github.com/aws/jsii/issues/826
 import software.amazon.awscdk.services.ssm.*;
 

Using existing SSM Parameters in your CDK app

You can reference existing SSM Parameter Store values that you want to use in your CDK app by using ssm.ParameterStoreString:

 // Example automatically generated. See https://github.com/aws/jsii/issues/826
 // Retrieve the latest value of the non-secret parameter
 // with name "/My/String/Parameter".
 String stringValue = ssm.StringParameter.fromStringParameterAttributes(this, 'MyValue', {
       parameterName: '/My/Public/Parameter',
       // 'version' can be specified but is optional.
     }).getStringValue();
 String stringValueVersionFromToken = ssm.StringParameter.fromStringParameterAttributes(this, 'MyValueVersionFromToken', {
       parameterName: '/My/Public/Parameter',
       // parameter version from token
       version: parameterVersion,
     }).getStringValue();
 
 // Retrieve a specific version of the secret (SecureString) parameter.
 // 'version' is always required.
 IStringParameter secretValue = ssm.StringParameter.fromSecureStringParameterAttributes(this, "MySecureValue", new SecureStringParameterAttributes()
         .parameterName("/My/Secret/Parameter")
         .version(5));
 IStringParameter secretValueVersionFromToken = ssm.StringParameter.fromSecureStringParameterAttributes(this, "MySecureValueVersionFromToken", new SecureStringParameterAttributes()
         .parameterName("/My/Secret/Parameter")
         // parameter version from token
         .version(parameterVersion));
 

Creating new SSM Parameters in your CDK app

You can create either ssm.StringParameter or ssm.StringListParameters in a CDK app. These are public (not secret) values. Parameters of type SecretString cannot be created directly from a CDK application; if you want to provision secrets automatically, use Secrets Manager Secrets (see the @aws-cdk/aws-secretsmanager package).

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 StringParameter.Builder.create(stack, "Parameter")
         .allowedPattern(".*")
         .description("The value Foo")
         .parameterName("FooParameter")
         .stringValue("Foo")
         .tier(ssm.ParameterTier.getADVANCED())
         .build();
 

 // Example automatically generated. See https://github.com/aws/jsii/issues/826
 // Create a new SSM Parameter holding a String
 StringParameter param = new StringParameter(stack, "StringParameter", new StringParameterProps()
         // description: 'Some user-friendly description',
         // name: 'ParameterName',
         .stringValue("Initial parameter value"));
 
 // Grant read access to some Role
 param.grantRead(role);
 
 // Create a new SSM Parameter holding a StringList
 StringListParameter listParameter = new StringListParameter(stack, "StringListParameter", new StringListParameterProps()
         // description: 'Some user-friendly description',
         // name: 'ParameterName',
         .stringListValue(asList("Initial parameter value A", "Initial parameter value B")));
 

When specifying an allowedPattern, the values provided as string literals are validated against the pattern and an exception is raised if a value provided does not comply.

Skip navigation links