From 4317f9c4ed90b109e66421b41cfa07349949fbe6 Mon Sep 17 00:00:00 2001 From: So Nishimura Date: Sat, 6 Jul 2024 17:25:16 +0900 Subject: [PATCH 1/3] feat(sns): add validation for Topic displayName --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 4 ++++ packages/aws-cdk-lib/aws-sns/test/sns.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index a57569060be8d..e7eb0d71a7bd6 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -296,6 +296,10 @@ export class Topic extends TopicBase { throw new Error(`signatureVersion must be "1" or "2", received: "${props.signatureVersion}"`); } + if (props.displayName && !Token.isUnresolved(props.displayName) && props.displayName.length > 100) { + throw new Error(`displayName must be less than or equal to 100 characters, got ${props.displayName.length}`); + } + const resource = new CfnTopic(this, 'Resource', { archivePolicy: props.messageRetentionPeriodInDays ? { MessageRetentionPeriod: props.messageRetentionPeriodInDays, diff --git a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts index fc1f1cd4c2846..6c8f04fb096b6 100644 --- a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts +++ b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts @@ -176,6 +176,16 @@ describe('Topic', () => { signatureVersion: '3', })).toThrow(/signatureVersion must be "1" or "2", received: "3"/); }); + + test('throw error when displayName is too long', () => { + const stack = new cdk.Stack(); + + expect(() => { + new sns.Topic(stack, 'MyTopic', { + displayName: 'a'.repeat(101), + }); + }).toThrow('displayName must be less than or equal to 100 characters, got 101'); + }); }); test('can add a policy to the topic', () => { From 278f0f783265c8861456c8078d56e9d5386d038a Mon Sep 17 00:00:00 2001 From: So Nishimura Date: Wed, 10 Jul 2024 19:28:41 +0900 Subject: [PATCH 2/3] feat(sns): add description for displayName --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index e7eb0d71a7bd6..12702d8e3d6bb 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -12,6 +12,9 @@ export interface TopicProps { /** * A developer-defined string that can be used to identify this SNS topic. * + * The display name to use for an Amazon SNS topic with SMS subscriptions. The display name must be maximum 100 characters long, including hyphens (-), + * underscores (_), spaces, and tabs. + * * @default None */ readonly displayName?: string; From af4e2bb8ddb07a1a68013e8e14b1db75d50ecd56 Mon Sep 17 00:00:00 2001 From: So Nishimura Date: Wed, 10 Jul 2024 19:38:04 +0900 Subject: [PATCH 3/3] feat(sns): update description for displayName --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-sns/lib/topic.ts b/packages/aws-cdk-lib/aws-sns/lib/topic.ts index 12702d8e3d6bb..f78b32bf8cfe3 100644 --- a/packages/aws-cdk-lib/aws-sns/lib/topic.ts +++ b/packages/aws-cdk-lib/aws-sns/lib/topic.ts @@ -12,7 +12,7 @@ export interface TopicProps { /** * A developer-defined string that can be used to identify this SNS topic. * - * The display name to use for an Amazon SNS topic with SMS subscriptions. The display name must be maximum 100 characters long, including hyphens (-), + * The display name must be maximum 100 characters long, including hyphens (-), * underscores (_), spaces, and tabs. * * @default None