From f9fd00cd3401e5264518b3409b1130eea976e2db Mon Sep 17 00:00:00 2001 From: Tatsuya Mori <tamori@amazon.com> Date: Sat, 27 Jul 2024 09:05:43 +0900 Subject: [PATCH 1/2] docs(ecs): describe default tag value for fromEcrRepository method (#30926) ### Description of changes If we don't specify the tag parameter for fromEcrRepository method, `latest` is used as default value. https://github.com/aws/aws-cdk/blob/c8e5924bbc83b91b929838518f4955dd3bbb884f/packages/aws-cdk-lib/aws-ecs/lib/container-image.ts#L19-L24 However, currently this behavior is not described in document. https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerImage.html#static-fromwbrecrwbrrepositoryrepository-tag I'm adding the description regarding this default value. ### 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* --- packages/aws-cdk-lib/aws-ecs/lib/container-image.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs/lib/container-image.ts b/packages/aws-cdk-lib/aws-ecs/lib/container-image.ts index 7ba6d6bf320d7..5c710df600727 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/container-image.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/container-image.ts @@ -18,6 +18,8 @@ export abstract class ContainerImage { /** * Reference an image in an ECR repository + * + * @param tag If you don't specify this parameter, `latest` is used as default. */ public static fromEcrRepository(repository: ecr.IRepository, tag: string = 'latest') { return new EcrImage(repository, tag); From da2ec75f6bc8f2e28b07cdf1307b22c83bb652d5 Mon Sep 17 00:00:00 2001 From: soso <sonishimura15@gmail.com> Date: Mon, 29 Jul 2024 11:44:46 +0900 Subject: [PATCH 2/2] feat(sns): add validation of `displayName` for topic (#30770) ### Issue # (if applicable) -- ### Reason for this change Display errors before deploying ### Description of changes - Implement length check for displayName (maximum 100 characters long) - [AWS::SNS::Topic](https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-sns-topic.html#cfn-sns-topic-displayname) ### Description of how you validated changes I added unit tests and confirmed all tests passed. ### 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* --- packages/aws-cdk-lib/aws-sns/lib/topic.ts | 7 +++++++ packages/aws-cdk-lib/aws-sns/test/sns.test.ts | 10 ++++++++++ 2 files changed, 17 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..f78b32bf8cfe3 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 must be maximum 100 characters long, including hyphens (-), + * underscores (_), spaces, and tabs. + * * @default None */ readonly displayName?: string; @@ -296,6 +299,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', () => {