Skip to content

Commit 0247013

Browse files
authored
chore(ssm): update simple name description and documentation (#30653)
### Issue # (if applicable) Closes #28778. ### Reason for this change There are issues with SSM `StringParameter` where the parameter ARN would have missing `/` or duplicate `/` depending on the setup of `simpleName` with unresolved tokens in the parameter name. ### Description of changes Update README and docstring to explain to users when and how to correctly use `simpleName` parameter. ### Description of how you validated changes No code changes made. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent dfc12aa commit 0247013

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

packages/aws-cdk-lib/aws-ssm/README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# AWS Systems Manager Construct Library
22

3-
43
This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.
54

65
## Using existing SSM Parameters in your CDK app
@@ -143,3 +142,32 @@ When specifying an `allowedPattern`, the values provided as string literals
143142
are validated against the pattern and an exception is raised if a value
144143
provided does not comply.
145144

145+
## Using Tokens in parameter name
146+
147+
When using [CDK Tokens](https://docs.aws.amazon.com/cdk/v2/guide/tokens.html) in parameter name,
148+
you need to explicitly set the `simpleName` property. Setting `simpleName` to an incorrect boolean
149+
value may result in unexpected behaviours, such as having duplicate '/' in the parameter ARN
150+
or missing a '/' in the parameter ARN.
151+
152+
`simpleName` is used to indicates whether the parameter name is a simple name. A parameter name
153+
without any '/' is considered a simple name, thus you should set `simpleName` to `true`.
154+
If the parameter name includes '/', set `simpleName` to `false`.
155+
156+
```ts
157+
import * as lambda from 'aws-cdk-lib/aws-lambda';
158+
159+
const simpleParameter = new ssm.StringParameter(this, 'StringParameter', {
160+
// the parameter name doesn't contain any '/'
161+
parameterName: 'parameter',
162+
stringValue: 'SOME_VALUE',
163+
simpleName: true, // set `simpleName` to true
164+
});
165+
166+
declare const func: lambda.IFunction;
167+
const nonSimpleParameter = new ssm.StringParameter(this, 'StringParameter', {
168+
// the parameter name contains '/'
169+
parameterName: `/${func.functionName}/my/app/param`,
170+
stringValue: 'SOME_VALUE',
171+
simpleName: false, // set `simpleName` to false
172+
});
173+
```

packages/aws-cdk-lib/aws-ssm/lib/parameter.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ export interface ParameterOptions {
9999
readonly parameterName?: string;
100100

101101
/**
102-
* Indicates if the parameter name is a simple name (i.e. does not include "/"
103-
* separators).
102+
* Indicates whether the parameter name is a simple name. A parameter name
103+
* without any "/" is considered a simple name. If the parameter name includes
104+
* "/", setting simpleName to true might cause unintended issues such
105+
* as duplicate "/" in the resulting ARN.
104106
*
105107
* This is required only if `parameterName` is a token, which means we
106108
* are unable to detect if the name is simple or "path-like" for the purpose
@@ -337,8 +339,10 @@ export interface CommonStringParameterAttributes {
337339
readonly parameterName: string;
338340

339341
/**
340-
* Indicates if the parameter name is a simple name (i.e. does not include "/"
341-
* separators).
342+
* Indicates whether the parameter name is a simple name. A parameter name
343+
* without any "/" is considered a simple name. If the parameter name includes
344+
* "/", setting simpleName to true might cause unintended issues such
345+
* as duplicate "/" in the resulting ARN.
342346
*
343347
* This is required only if `parameterName` is a token, which means we
344348
* are unable to detect if the name is simple or "path-like" for the purpose

0 commit comments

Comments
 (0)