From 7f7df3b4b8adfca55899e1e9a9016e47ecf67306 Mon Sep 17 00:00:00 2001 From: yuanhaoz Date: Mon, 24 Jun 2024 15:14:23 -0700 Subject: [PATCH 1/4] chore(ssm): update simple name description and documentation --- packages/aws-cdk-lib/aws-ssm/README.md | 28 +++++++++++++++++++ packages/aws-cdk-lib/aws-ssm/lib/parameter.ts | 12 +++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index e70e424f0573b..42cbb499dd90b 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -143,3 +143,31 @@ 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. +## Using Tokens in parameter name + +When using [CDK Tokens](https://docs.aws.amazon.com/cdk/v2/guide/tokens.html) in parameter name, +you need to explicitly set `simpleName` property. Setting `simpleName` to incorrect boolean +value may result in unexpected behaviours, such as getting duplicate '/' in the parameter ARN +or missing '/' in the parameter ARN. + +`simpleName` is used to indicates whether the parameter name is a simple name. A parameter name +without any '/' is considered a simple name, thus you should set `simpleName` to `true`. +If the parameter name includes '/', set `simpleName` to `false`. + +```ts +declare const func: lambda.IFunction; + +const simpleParameter = new ssm.StringParameter(this, 'StringParameter', { + // the parameter name is simple + parameterName: 'parameter', + stringValue: 'SOME_VALUE', + simpleName: true, // set `simpleName` to true +}); + +const nonSimpleParameter = new ssm.StringParameter(this, 'StringParameter', { + // the parameter name is not simple + parameterName: `/${func.functionName}/my/app/param`, + stringValue: 'SOME_VALUE', + simpleName: false, // set `simpleName` to false +}); +``` diff --git a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts index 1972b605665fc..5b0e02ea13e47 100644 --- a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts +++ b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts @@ -99,8 +99,10 @@ export interface ParameterOptions { readonly parameterName?: string; /** - * Indicates if the parameter name is a simple name (i.e. does not include "/" - * separators). + * Indicates whether the parameter name is a simple name. A parameter name + * without any "/" is considered a simple name. If the parameter name includes + * "/", setting simpleName to true might cause unintended issues, such + * as duplicate "/" in the resulting ARN. * * This is required only if `parameterName` is a token, which means we * are unable to detect if the name is simple or "path-like" for the purpose @@ -337,8 +339,10 @@ export interface CommonStringParameterAttributes { readonly parameterName: string; /** - * Indicates if the parameter name is a simple name (i.e. does not include "/" - * separators). + * Indicates whether the parameter name is a simple name. A parameter name + * without any "/" is considered a simple name. If the parameter name includes + * "/", setting simpleName to true might cause unintended issues, such + * as duplicate "/" in the resulting ARN. * * This is required only if `parameterName` is a token, which means we * are unable to detect if the name is simple or "path-like" for the purpose From 728b952554a42539aa67653cf9cb3a26294ce431 Mon Sep 17 00:00:00 2001 From: yuanhaoz Date: Mon, 24 Jun 2024 16:54:10 -0700 Subject: [PATCH 2/4] Update readme --- packages/aws-cdk-lib/aws-ssm/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index 42cbb499dd90b..8bd1f196ee776 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -1,6 +1,5 @@ # AWS Systems Manager Construct Library - This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. ## Using existing SSM Parameters in your CDK app @@ -155,7 +154,7 @@ without any '/' is considered a simple name, thus you should set `simpleName` to If the parameter name includes '/', set `simpleName` to `false`. ```ts -declare const func: lambda.IFunction; +import * as lambda from 'aws-cdk-lib/aws-lambda'; const simpleParameter = new ssm.StringParameter(this, 'StringParameter', { // the parameter name is simple @@ -164,6 +163,7 @@ const simpleParameter = new ssm.StringParameter(this, 'StringParameter', { simpleName: true, // set `simpleName` to true }); +declare const func: lambda.IFunction; const nonSimpleParameter = new ssm.StringParameter(this, 'StringParameter', { // the parameter name is not simple parameterName: `/${func.functionName}/my/app/param`, From d7b77c74d02a8a56c7a1621360c12050cc3a5b7b Mon Sep 17 00:00:00 2001 From: yuanhaoz Date: Wed, 26 Jun 2024 14:03:00 -0700 Subject: [PATCH 3/4] update comments --- packages/aws-cdk-lib/aws-ssm/README.md | 10 +++++----- packages/aws-cdk-lib/aws-ssm/lib/parameter.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ssm/README.md b/packages/aws-cdk-lib/aws-ssm/README.md index 8bd1f196ee776..0f678c449c756 100644 --- a/packages/aws-cdk-lib/aws-ssm/README.md +++ b/packages/aws-cdk-lib/aws-ssm/README.md @@ -145,9 +145,9 @@ provided does not comply. ## Using Tokens in parameter name When using [CDK Tokens](https://docs.aws.amazon.com/cdk/v2/guide/tokens.html) in parameter name, -you need to explicitly set `simpleName` property. Setting `simpleName` to incorrect boolean -value may result in unexpected behaviours, such as getting duplicate '/' in the parameter ARN -or missing '/' in the parameter ARN. +you need to explicitly set the `simpleName` property. Setting `simpleName` to an incorrect boolean +value may result in unexpected behaviours, such as having duplicate '/' in the parameter ARN +or missing a '/' in the parameter ARN. `simpleName` is used to indicates whether the parameter name is a simple name. A parameter name without any '/' is considered a simple name, thus you should set `simpleName` to `true`. @@ -157,7 +157,7 @@ If the parameter name includes '/', set `simpleName` to `false`. import * as lambda from 'aws-cdk-lib/aws-lambda'; const simpleParameter = new ssm.StringParameter(this, 'StringParameter', { - // the parameter name is simple + // the parameter name doesn't contain any '/' parameterName: 'parameter', stringValue: 'SOME_VALUE', simpleName: true, // set `simpleName` to true @@ -165,7 +165,7 @@ const simpleParameter = new ssm.StringParameter(this, 'StringParameter', { declare const func: lambda.IFunction; const nonSimpleParameter = new ssm.StringParameter(this, 'StringParameter', { - // the parameter name is not simple + // the parameter name contains '/' parameterName: `/${func.functionName}/my/app/param`, stringValue: 'SOME_VALUE', simpleName: false, // set `simpleName` to false diff --git a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts index 5b0e02ea13e47..a9692913b8806 100644 --- a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts +++ b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts @@ -341,7 +341,7 @@ export interface CommonStringParameterAttributes { /** * Indicates whether the parameter name is a simple name. A parameter name * without any "/" is considered a simple name. If the parameter name includes - * "/", setting simpleName to true might cause unintended issues, such + * "/", setting simpleName to true might cause unintended issues such * as duplicate "/" in the resulting ARN. * * This is required only if `parameterName` is a token, which means we From b61fcea4862e9461d0b31f2d528165b50d0e8065 Mon Sep 17 00:00:00 2001 From: paulhcsun <47882901+paulhcsun@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:08:10 -0700 Subject: [PATCH 4/4] Update packages/aws-cdk-lib/aws-ssm/lib/parameter.ts --- packages/aws-cdk-lib/aws-ssm/lib/parameter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts index a9692913b8806..f4087515bc724 100644 --- a/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts +++ b/packages/aws-cdk-lib/aws-ssm/lib/parameter.ts @@ -101,7 +101,7 @@ export interface ParameterOptions { /** * Indicates whether the parameter name is a simple name. A parameter name * without any "/" is considered a simple name. If the parameter name includes - * "/", setting simpleName to true might cause unintended issues, such + * "/", setting simpleName to true might cause unintended issues such * as duplicate "/" in the resulting ARN. * * This is required only if `parameterName` is a token, which means we