From aa8484a154baea87f223c4b22135f3a845b836b3 Mon Sep 17 00:00:00 2001 From: yoshi Date: Sat, 2 Mar 2024 04:29:00 +0900 Subject: [PATCH 1/3] fix(sqs): `redrivePermission` is set to `byQueue` no matter what value is specified (#29130) ### Issue #29129 Closes #29129. ### Reason for this change When `redriveAllowPolicy.redrivePermission` is specified, any value will be output to template as `byQueue` ### Description of changes 1. Fix the evaluation order by enclosing the ternary operators in parentheses ```typescript ?? (props.redriveAllowPolicy.sourceQueues ? RedrivePermission.BY_QUEUE : RedrivePermission.ALLOW_ALL), ``` 2. Added a test case in `packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts` when redrivePermission is specified other than `BY_QUEUE`. 3. Added an integ test case in `packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts` ### Description of how you validated changes Added a test case in `packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts` when redrivePermission is specified other than `BY_QUEUE`. Added an integ test case in `packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts` And ran the test case. ### 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* --- .../aws-cdk-sqs.template.json | 10 +++++++ .../test/integ.sqs-source-queue-permission.ts | 12 +++++++-- packages/aws-cdk-lib/aws-sqs/lib/queue.ts | 2 +- packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts | 27 +++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.js.snapshot/aws-cdk-sqs.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.js.snapshot/aws-cdk-sqs.template.json index a116bcb48f618..a17bfbfefa270 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.js.snapshot/aws-cdk-sqs.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.js.snapshot/aws-cdk-sqs.template.json @@ -2,11 +2,21 @@ "Resources": { "SourceQueue1F4BBA4BB": { "Type": "AWS::SQS::Queue", + "Properties": { + "RedriveAllowPolicy": { + "redrivePermission": "allowAll" + } + }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" }, "SourceQueue22481CB5A": { "Type": "AWS::SQS::Queue", + "Properties": { + "RedriveAllowPolicy": { + "redrivePermission": "denyAll" + } + }, "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts index e6079ba21f67e..3ff61390fd95d 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts @@ -7,8 +7,16 @@ const app = new App(); const stack = new Stack(app, 'aws-cdk-sqs'); -const sourceQueue1 = new Queue(stack, 'SourceQueue1'); -const sourceQueue2 = new Queue(stack, 'SourceQueue2'); +const sourceQueue1 = new Queue(stack, 'SourceQueue1', { + redriveAllowPolicy: { + redrivePermission: RedrivePermission.ALLOW_ALL, + }, +}); +const sourceQueue2 = new Queue(stack, 'SourceQueue2', { + redriveAllowPolicy: { + redrivePermission: RedrivePermission.DENY_ALL, + }, +}); new Queue(stack, 'DeadLetterQueue', { redriveAllowPolicy: { diff --git a/packages/aws-cdk-lib/aws-sqs/lib/queue.ts b/packages/aws-cdk-lib/aws-sqs/lib/queue.ts index c8a9c758978a9..f425536f89937 100644 --- a/packages/aws-cdk-lib/aws-sqs/lib/queue.ts +++ b/packages/aws-cdk-lib/aws-sqs/lib/queue.ts @@ -411,7 +411,7 @@ export class Queue extends QueueBase { redrivePermission: props.redriveAllowPolicy.redrivePermission // When `sourceQueues` is provided in `redriveAllowPolicy`, `redrivePermission` defaults to allow specified queues (`BY_QUEUE`); // otherwise, it defaults to allow all queues (`ALLOW_ALL`). - ?? props.redriveAllowPolicy.sourceQueues ? RedrivePermission.BY_QUEUE : RedrivePermission.ALLOW_ALL, + ?? (props.redriveAllowPolicy.sourceQueues ? RedrivePermission.BY_QUEUE : RedrivePermission.ALLOW_ALL), sourceQueueArns: props.redriveAllowPolicy.sourceQueues?.map(q => q.queueArn), } : undefined; diff --git a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts index 956c8a77cdd7a..0ae7bc2919ef5 100644 --- a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts +++ b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts @@ -753,6 +753,33 @@ describe('redriveAllowPolicy', () => { }); }); + test.each([ + [sqs.RedrivePermission.ALLOW_ALL, 'allowAll'], + [sqs.RedrivePermission.DENY_ALL, 'denyAll'], + ])('redrive permission can be set to %s', (permission, expected) => { + const stack = new Stack(); + new sqs.Queue(stack, 'Queue', { + redriveAllowPolicy: { + redrivePermission: permission, + }, + }); + + Template.fromStack(stack).templateMatches({ + 'Resources': { + 'Queue4A7E3555': { + 'Type': 'AWS::SQS::Queue', + 'Properties': { + 'RedriveAllowPolicy': { + 'redrivePermission': expected, + }, + }, + 'UpdateReplacePolicy': 'Delete', + 'DeletionPolicy': 'Delete', + }, + }, + }); + }); + test('explicit specification of dead letter source queues', () => { const stack = new Stack(); const sourceQueue1 = new sqs.Queue(stack, 'SourceQueue1'); From 7205143d563449ab211406da04d99bbbcdc7c8cc Mon Sep 17 00:00:00 2001 From: Michael Sambol Date: Fri, 1 Mar 2024 13:19:51 -0700 Subject: [PATCH 2/3] fix(batch): windows does not support readonlyRootFilesystem (#29145) Here's from the k8s docs: ``` securityContext.readOnlyRootFilesystem - not possible on Windows; write access is required for registry & system processes to run inside the container ``` Closes #29140. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../manifest.json | 25 +- .../stack.assets.json | 4 +- .../stack.template.json | 100 ++++ .../tree.json | 504 ++++++++++++------ .../test/integ.ecs-job-definition.ts | 12 + .../aws-batch/lib/ecs-container-definition.ts | 14 +- .../test/ecs-container-definition.test.ts | 29 +- .../aws-ecs/lib/runtime-platform.ts | 9 +- 8 files changed, 525 insertions(+), 172 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/manifest.json index d4e5db68eb0de..4b40b7a3b001e 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/80ca79d29007dc0a645c6568c47e0730a748e22b27eaba47a7336b97d459edcc.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9b59badf02feb83b2f2747da9bbab479669d1efa47acadf76785d017660f7d03.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -247,10 +247,7 @@ "/stack/ECSFargateJobDefn/Resource": [ { "type": "aws:cdk:logicalId", - "data": "ECSFargateJobDefn327BE725", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" - ] + "data": "ECSFargateJobDefn327BE725" } ], "/stack/EcsDockerContainer/ExecutionRole/Resource": [ @@ -271,6 +268,24 @@ "data": "ECSDockerJobDefnF388CFCF" } ], + "/stack/WindowsFargateContainer/ExecutionRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WindowsFargateContainerExecutionRoleAE15A6C1" + } + ], + "/stack/WindowsFargateContainer/ExecutionRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WindowsFargateContainerExecutionRoleDefaultPolicyA16F3283" + } + ], + "/stack/WindowsJobDefinitio/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "WindowsJobDefinitio0652E08A" + } + ], "/stack/BootstrapVersion": [ { "type": "aws:cdk:logicalId", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.assets.json index be9330c4ed096..5af4252f1a2d2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.assets.json @@ -1,7 +1,7 @@ { "version": "36.0.0", "files": { - "80ca79d29007dc0a645c6568c47e0730a748e22b27eaba47a7336b97d459edcc": { + "9b59badf02feb83b2f2747da9bbab479669d1efa47acadf76785d017660f7d03": { "source": { "path": "stack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "80ca79d29007dc0a645c6568c47e0730a748e22b27eaba47a7336b97d459edcc.json", + "objectKey": "9b59badf02feb83b2f2747da9bbab479669d1efa47acadf76785d017660f7d03.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.template.json index 07857e0e45000..4f3da7e9b5dcc 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/stack.template.json @@ -997,6 +997,106 @@ "Timeout": {}, "Type": "container" } + }, + "WindowsFargateContainerExecutionRoleAE15A6C1": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "WindowsFargateContainerExecutionRoleDefaultPolicyA16F3283": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/batch/job:*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "WindowsFargateContainerExecutionRoleDefaultPolicyA16F3283", + "Roles": [ + { + "Ref": "WindowsFargateContainerExecutionRoleAE15A6C1" + } + ] + } + }, + "WindowsJobDefinitio0652E08A": { + "Type": "AWS::Batch::JobDefinition", + "Properties": { + "ContainerProperties": { + "Environment": [], + "ExecutionRoleArn": { + "Fn::GetAtt": [ + "WindowsFargateContainerExecutionRoleAE15A6C1", + "Arn" + ] + }, + "FargatePlatformConfiguration": {}, + "Image": "mcr.microsoft.com/dotnet/framework/runtime:4.7.2", + "NetworkConfiguration": { + "AssignPublicIp": "DISABLED" + }, + "ResourceRequirements": [ + { + "Type": "MEMORY", + "Value": "8192" + }, + { + "Type": "VCPU", + "Value": "2" + } + ], + "RuntimePlatform": { + "CpuArchitecture": "X86_64", + "OperatingSystemFamily": "WINDOWS_SERVER_2019_FULL" + } + }, + "JobDefinitionName": "windows-job-definition", + "PlatformCapabilities": [ + "FARGATE" + ], + "RetryStrategy": {}, + "Timeout": {}, + "Type": "container" + } } }, "Parameters": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/tree.json index a6452a3856934..6d0429bfdff10 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.js.snapshot/tree.json @@ -31,8 +31,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnVPC", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PublicSubnet1": { @@ -75,16 +75,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "stack/vpc/PublicSubnet1/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -105,8 +105,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -124,8 +124,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -144,8 +144,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EIP": { @@ -164,8 +164,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "NATGateway": { @@ -192,14 +192,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PublicSubnet2": { @@ -242,16 +242,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "stack/vpc/PublicSubnet2/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -272,8 +272,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -291,8 +291,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -311,8 +311,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EIP": { @@ -331,8 +331,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnEIP", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "NATGateway": { @@ -359,14 +359,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnNatGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PublicSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PrivateSubnet1": { @@ -409,16 +409,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "stack/vpc/PrivateSubnet1/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -439,8 +439,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -458,8 +458,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -478,14 +478,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "PrivateSubnet2": { @@ -528,16 +528,16 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Acl": { "id": "Acl", "path": "stack/vpc/PrivateSubnet2/Acl", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTable": { @@ -558,8 +558,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRouteTable", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "RouteTableAssociation": { @@ -577,8 +577,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSubnetRouteTableAssociation", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultRoute": { @@ -597,14 +597,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnRoute", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.PrivateSubnet", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "IGW": { @@ -622,8 +622,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnInternetGateway", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "VPCGW": { @@ -641,14 +641,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnVPCGatewayAttachment", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.Vpc", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "myFileSystem": { @@ -691,8 +691,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_efs.CfnFileSystem", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EfsSecurityGroup": { @@ -725,14 +725,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EfsMountTarget-PrivateSubnet1": { @@ -758,8 +758,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_efs.CfnMountTarget", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EfsMountTarget-PrivateSubnet2": { @@ -785,14 +785,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_efs.CfnMountTarget", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_efs.FileSystem", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "mySecret": { @@ -809,14 +809,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_secretsmanager.CfnSecret", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_secretsmanager.Secret", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "anotherSecret": { @@ -833,14 +833,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_secretsmanager.CfnSecret", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_secretsmanager.Secret", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ssm": { @@ -858,14 +858,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ssm.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ssm.StringParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "myContainer": { @@ -880,8 +880,8 @@ "id": "ImportExecutionRole", "path": "stack/myContainer/ExecutionRole/ImportExecutionRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Resource": { @@ -905,8 +905,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultPolicy": { @@ -1007,34 +1007,34 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Policy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "batchDefaultLogGroup": { "id": "batchDefaultLogGroup", "path": "stack/myContainer/batchDefaultLogGroup", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.EcsEc2ContainerDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ECSJobDefn": { @@ -1167,14 +1167,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.CfnJobDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.EcsJobDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "myFargateContainer": { @@ -1189,8 +1189,8 @@ "id": "ImportExecutionRole", "path": "stack/myFargateContainer/ExecutionRole/ImportExecutionRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Resource": { @@ -1214,8 +1214,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultPolicy": { @@ -1269,34 +1269,34 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Policy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "batchDefaultLogGroup": { "id": "batchDefaultLogGroup", "path": "stack/myFargateContainer/batchDefaultLogGroup", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.EcsFargateContainerDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ECSFargateJobDefn": { @@ -1378,14 +1378,14 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.CfnJobDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.EcsJobDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "dockerImageAsset": { @@ -1396,22 +1396,22 @@ "id": "Staging", "path": "stack/dockerImageAsset/Staging", "constructInfo": { - "fqn": "aws-cdk-lib.AssetStaging", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Repository": { "id": "Repository", "path": "stack/dockerImageAsset/Repository", "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecr.RepositoryBase", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_ecr_assets.DockerImageAsset", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "EcsDockerContainer": { @@ -1426,8 +1426,8 @@ "id": "ImportExecutionRole", "path": "stack/EcsDockerContainer/ExecutionRole/ImportExecutionRole", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "Resource": { @@ -1451,8 +1451,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnRole", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "DefaultPolicy": { @@ -1542,34 +1542,34 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.CfnPolicy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Policy", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_iam.Role", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "batchDefaultLogGroup": { "id": "batchDefaultLogGroup", "path": "stack/EcsDockerContainer/batchDefaultLogGroup", "constructInfo": { - "fqn": "aws-cdk-lib.Resource", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.EcsEc2ContainerDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "ECSDockerJobDefn": { @@ -1614,36 +1614,216 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.CfnJobDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_batch.EcsJobDefinition", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "WindowsFargateContainer": { + "id": "WindowsFargateContainer", + "path": "stack/WindowsFargateContainer", + "children": { + "ExecutionRole": { + "id": "ExecutionRole", + "path": "stack/WindowsFargateContainer/ExecutionRole", + "children": { + "ImportExecutionRole": { + "id": "ImportExecutionRole", + "path": "stack/WindowsFargateContainer/ExecutionRole/ImportExecutionRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "stack/WindowsFargateContainer/ExecutionRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultPolicy": { + "id": "DefaultPolicy", + "path": "stack/WindowsFargateContainer/ExecutionRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "stack/WindowsFargateContainer/ExecutionRole/DefaultPolicy/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Policy", + "aws:cdk:cloudformation:props": { + "policyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/batch/job:*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "WindowsFargateContainerExecutionRoleDefaultPolicyA16F3283", + "roles": [ + { + "Ref": "WindowsFargateContainerExecutionRoleAE15A6C1" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "batchDefaultLogGroup": { + "id": "batchDefaultLogGroup", + "path": "stack/WindowsFargateContainer/batchDefaultLogGroup", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "WindowsJobDefinitio": { + "id": "WindowsJobDefinitio", + "path": "stack/WindowsJobDefinitio", + "children": { + "Resource": { + "id": "Resource", + "path": "stack/WindowsJobDefinitio/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Batch::JobDefinition", + "aws:cdk:cloudformation:props": { + "containerProperties": { + "image": "mcr.microsoft.com/dotnet/framework/runtime:4.7.2", + "environment": [], + "executionRoleArn": { + "Fn::GetAtt": [ + "WindowsFargateContainerExecutionRoleAE15A6C1", + "Arn" + ] + }, + "resourceRequirements": [ + { + "type": "MEMORY", + "value": "8192" + }, + { + "type": "VCPU", + "value": "2" + } + ], + "fargatePlatformConfiguration": {}, + "networkConfiguration": { + "assignPublicIp": "DISABLED" + }, + "runtimePlatform": { + "cpuArchitecture": "X86_64", + "operatingSystemFamily": "WINDOWS_SERVER_2019_FULL" + } + }, + "jobDefinitionName": "windows-job-definition", + "platformCapabilities": [ + "FARGATE" + ], + "retryStrategy": {}, + "timeout": {}, + "type": "container" + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "stack/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "stack/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "BatchEcsJobDefinitionTest": { @@ -1670,22 +1850,22 @@ "id": "BootstrapVersion", "path": "BatchEcsJobDefinitionTest/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnParameter", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", "path": "BatchEcsJobDefinitionTest/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { - "fqn": "aws-cdk-lib.CfnRule", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, "constructInfo": { - "fqn": "aws-cdk-lib.Stack", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } }, @@ -1710,8 +1890,8 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.App", - "version": "0.0.0" + "fqn": "constructs.Construct", + "version": "10.3.0" } } } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.ts index ec2ac7fdeaec8..42bd10cb5ebfc 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-batch/test/integ.ecs-job-definition.ts @@ -92,6 +92,18 @@ new batch.EcsJobDefinition(stack, 'ECSDockerJobDefn', { }), }); +// can successfully launch a Windows container +new batch.EcsJobDefinition(stack, 'WindowsJobDefinitio', { + jobDefinitionName: 'windows-job-definition', + container: new batch.EcsFargateContainerDefinition(stack, 'WindowsFargateContainer', { + image: ecs.ContainerImage.fromRegistry('mcr.microsoft.com/dotnet/framework/runtime:4.7.2'), + memory: Size.gibibytes(8), + cpu: 2, + fargateCpuArchitecture: ecs.CpuArchitecture.X86_64, + fargateOperatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2019_FULL, + }), +}); + new integ.IntegTest(app, 'BatchEcsJobDefinitionTest', { testCases: [stack], }); diff --git a/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts b/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts index 8d5369d7c88d9..2253cb7d4868c 100644 --- a/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts +++ b/packages/aws-cdk-lib/aws-batch/lib/ecs-container-definition.ts @@ -1057,6 +1057,11 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im this.fargateCpuArchitecture = props.fargateCpuArchitecture; this.fargateOperatingSystemFamily = props.fargateOperatingSystemFamily; + if (this.fargateOperatingSystemFamily?.isWindows() && this.readonlyRootFilesystem) { + // see https://kubernetes.io/docs/concepts/windows/intro/ + throw new Error('Readonly root filesystem is not possible on Windows; write access is required for registry & system processes to run inside the container'); + } + // validates ephemeralStorageSize is within limits if (props.ephemeralStorageSize) { if (props.ephemeralStorageSize.toGibibytes() > 200) { @@ -1071,7 +1076,7 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im * @internal */ public _renderContainerDefinition(): CfnJobDefinition.ContainerPropertiesProperty { - return { + let containerDef = { ...super._renderContainerDefinition(), ephemeralStorage: this.ephemeralStorageSize? { sizeInGiB: this.ephemeralStorageSize?.toGibibytes(), @@ -1087,6 +1092,13 @@ export class EcsFargateContainerDefinition extends EcsContainerDefinitionBase im operatingSystemFamily: this.fargateOperatingSystemFamily?._operatingSystemFamily, }, }; + + // readonlyRootFilesystem isn't applicable to Windows, see https://kubernetes.io/docs/concepts/windows/intro/ + if (this.fargateOperatingSystemFamily?.isWindows()) { + containerDef.readonlyRootFilesystem = undefined; + } + + return containerDef; }; } diff --git a/packages/aws-cdk-lib/aws-batch/test/ecs-container-definition.test.ts b/packages/aws-cdk-lib/aws-batch/test/ecs-container-definition.test.ts index 038ba05965020..c771cd19a3d90 100644 --- a/packages/aws-cdk-lib/aws-batch/test/ecs-container-definition.test.ts +++ b/packages/aws-cdk-lib/aws-batch/test/ecs-container-definition.test.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { capitalizePropertyNames } from './utils'; import { Size, Stack } from '../..'; import * as cdk from '../..'; -import { Template } from '../../assertions'; +import { Match, Template } from '../../assertions'; import { Vpc } from '../../aws-ec2'; import * as ecr from '../../aws-ecr'; import { DockerImageAsset } from '../../aws-ecr-assets'; @@ -1067,4 +1067,31 @@ describe('Fargate containers', () => { }), })).toThrow("ECS Fargate container 'EcsFargateContainer2' specifies 'ephemeralStorageSize' at 201 > 200 GB"); }); + + test('readonlyRootFilesystem can\'t be true with Windows family', () => { + expect(() => new EcsJobDefinition(stack, 'ECSJobDefn', { + container: new EcsFargateContainerDefinition(stack, 'EcsFargateContainer', { + ...defaultContainerProps, + readonlyRootFilesystem: true, + fargateOperatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2004_CORE, + }), + })).toThrow('Readonly root filesystem is not possible on Windows; write access is required for registry & system processes to run inside the container'); + }); + + test('readonlyRootFilesystem is undefined with Windows family', () => { + // WHEN + new EcsJobDefinition(stack, 'ECSJobDefn', { + container: new EcsFargateContainerDefinition(stack, 'EcsFargateContainer', { + ...defaultContainerProps, + fargateOperatingSystemFamily: ecs.OperatingSystemFamily.WINDOWS_SERVER_2004_CORE, + }), + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Batch::JobDefinition', { + ContainerProperties: { + ReadonlyRootFilesystem: Match.absent(), + }, + }); + }); }); diff --git a/packages/aws-cdk-lib/aws-ecs/lib/runtime-platform.ts b/packages/aws-cdk-lib/aws-ecs/lib/runtime-platform.ts index 37d760c62e657..250e64a1f9ca4 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/runtime-platform.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/runtime-platform.ts @@ -88,6 +88,13 @@ export class OperatingSystemFamily { * @param _operatingSystemFamily The operating system family. */ private constructor(public readonly _operatingSystemFamily: string) { } + + /** + * Returns true if the operating system family is Windows + */ + public isWindows(): boolean { + return this._operatingSystemFamily?.toLowerCase().startsWith('windows') ? true : false; + } } /** @@ -107,4 +114,4 @@ export interface RuntimePlatform { * @default - Undefined. */ readonly operatingSystemFamily?: OperatingSystemFamily; -} \ No newline at end of file +} From ebe2adff61c5cefcd4576bbc22c3b5d27b390d92 Mon Sep 17 00:00:00 2001 From: Ruvim Radchishin <39605354+ruvimrd@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:49:40 -0800 Subject: [PATCH 3/3] fix(cloudwatch): allow up to 30 dimensions for metric (#29341) ### Issue # (if applicable) Closes #29322. ### Reason for this change [AWS::CloudWatch::Alarm](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudwatch-alarm.html) allows up to 30 dimension items, while the L2 [construct](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.Metric.html#dimensions) for Metric allows up to 10. ### Description of changes Increased hard limit from 10 -> 30 ### Description of how you validated changes Updated unit test, added new integration test ### 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* --- ...k-cloudwatch-metric-dimensions.assets.json | 19 ++ ...cloudwatch-metric-dimensions.template.json | 105 ++++++++++ .../cdk.out | 1 + .../integ.json | 12 ++ .../manifest.json | 119 +++++++++++ ...efaultTestDeployAssert1196DF0F.assets.json | 19 ++ ...aultTestDeployAssert1196DF0F.template.json | 36 ++++ .../tree.json | 191 ++++++++++++++++++ .../test/integ.metric-with-dimensions.ts | 39 ++++ .../aws-cdk-lib/aws-cloudwatch/lib/metric.ts | 4 +- .../aws-cloudwatch/test/metrics.test.ts | 48 ++++- 11 files changed, 587 insertions(+), 6 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.assets.json new file mode 100644 index 0000000000000..16284e1e5e694 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "5b7b9376300e8d5da09834e7dfc97bf825e9354f770b53e1bc3e3d0a9de8f10c": { + "source": { + "path": "aws-cdk-cloudwatch-metric-dimensions.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "5b7b9376300e8d5da09834e7dfc97bf825e9354f770b53e1bc3e3d0a9de8f10c.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.template.json new file mode 100644 index 0000000000000..54d0bd59f3349 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/aws-cdk-cloudwatch-metric-dimensions.template.json @@ -0,0 +1,105 @@ +{ + "Resources": { + "queue": { + "Type": "AWS::SQS::Queue" + }, + "Alarm7103F465": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanOrEqualToThreshold", + "DatapointsToAlarm": 2, + "Dimensions": [ + { + "Name": "BlankD1", + "Value": "value1" + }, + { + "Name": "BlankD10", + "Value": "value10" + }, + { + "Name": "BlankD2", + "Value": "value2" + }, + { + "Name": "BlankD3", + "Value": "value3" + }, + { + "Name": "BlankD4", + "Value": "value4" + }, + { + "Name": "BlankD5", + "Value": "value5" + }, + { + "Name": "BlankD6", + "Value": "value6" + }, + { + "Name": "BlankD7", + "Value": "value7" + }, + { + "Name": "BlankD8", + "Value": "value8" + }, + { + "Name": "BlankD9", + "Value": "value9" + }, + { + "Name": "QueueName", + "Value": { + "Fn::GetAtt": [ + "queue", + "QueueName" + ] + } + } + ], + "EvaluationPeriods": 3, + "MetricName": "ApproximateNumberOfMessagesVisible", + "Namespace": "AWS/SQS", + "Period": 300, + "Statistic": "Average", + "Threshold": 100 + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/integ.json new file mode 100644 index 0000000000000..b3f4a8a62b0cf --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "metric-with-dimensions-test/DefaultTest": { + "stacks": [ + "aws-cdk-cloudwatch-metric-dimensions" + ], + "assertionStack": "metric-with-dimensions-test/DefaultTest/DeployAssert", + "assertionStackName": "metricwithdimensionstestDefaultTestDeployAssert1196DF0F" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/manifest.json new file mode 100644 index 0000000000000..31a9dc49d6c44 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/manifest.json @@ -0,0 +1,119 @@ +{ + "version": "36.0.0", + "artifacts": { + "aws-cdk-cloudwatch-metric-dimensions.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-cdk-cloudwatch-metric-dimensions.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-cdk-cloudwatch-metric-dimensions": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-cdk-cloudwatch-metric-dimensions.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/5b7b9376300e8d5da09834e7dfc97bf825e9354f770b53e1bc3e3d0a9de8f10c.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-cdk-cloudwatch-metric-dimensions.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "aws-cdk-cloudwatch-metric-dimensions.assets" + ], + "metadata": { + "/aws-cdk-cloudwatch-metric-dimensions/queue": [ + { + "type": "aws:cdk:logicalId", + "data": "queue" + } + ], + "/aws-cdk-cloudwatch-metric-dimensions/Alarm/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm7103F465" + } + ], + "/aws-cdk-cloudwatch-metric-dimensions/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-cdk-cloudwatch-metric-dimensions/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-cdk-cloudwatch-metric-dimensions" + }, + "metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "metricwithdimensionstestDefaultTestDeployAssert1196DF0F": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "metricwithdimensionstestDefaultTestDeployAssert1196DF0F.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets" + ], + "metadata": { + "/metric-with-dimensions-test/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/metric-with-dimensions-test/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "metric-with-dimensions-test/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets.json new file mode 100644 index 0000000000000..c673635d60504 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "metricwithdimensionstestDefaultTestDeployAssert1196DF0F.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/metricwithdimensionstestDefaultTestDeployAssert1196DF0F.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/tree.json new file mode 100644 index 0000000000000..f48626e919d06 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.js.snapshot/tree.json @@ -0,0 +1,191 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-cdk-cloudwatch-metric-dimensions": { + "id": "aws-cdk-cloudwatch-metric-dimensions", + "path": "aws-cdk-cloudwatch-metric-dimensions", + "children": { + "queue": { + "id": "queue", + "path": "aws-cdk-cloudwatch-metric-dimensions/queue", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnResource", + "version": "0.0.0" + } + }, + "Alarm": { + "id": "Alarm", + "path": "aws-cdk-cloudwatch-metric-dimensions/Alarm", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-cdk-cloudwatch-metric-dimensions/Alarm/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanOrEqualToThreshold", + "datapointsToAlarm": 2, + "dimensions": [ + { + "name": "BlankD1", + "value": "value1" + }, + { + "name": "BlankD10", + "value": "value10" + }, + { + "name": "BlankD2", + "value": "value2" + }, + { + "name": "BlankD3", + "value": "value3" + }, + { + "name": "BlankD4", + "value": "value4" + }, + { + "name": "BlankD5", + "value": "value5" + }, + { + "name": "BlankD6", + "value": "value6" + }, + { + "name": "BlankD7", + "value": "value7" + }, + { + "name": "BlankD8", + "value": "value8" + }, + { + "name": "BlankD9", + "value": "value9" + }, + { + "name": "QueueName", + "value": { + "Fn::GetAtt": [ + "queue", + "QueueName" + ] + } + } + ], + "evaluationPeriods": 3, + "metricName": "ApproximateNumberOfMessagesVisible", + "namespace": "AWS/SQS", + "period": 300, + "statistic": "Average", + "threshold": 100 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-cdk-cloudwatch-metric-dimensions/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-cdk-cloudwatch-metric-dimensions/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "metric-with-dimensions-test": { + "id": "metric-with-dimensions-test", + "path": "metric-with-dimensions-test", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "metric-with-dimensions-test/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "metric-with-dimensions-test/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "metric-with-dimensions-test/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "metric-with-dimensions-test/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "metric-with-dimensions-test/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.ts new file mode 100644 index 0000000000000..204d876e989b7 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.metric-with-dimensions.ts @@ -0,0 +1,39 @@ +// Creates an Alarm with a Metric that contains 11 dimensions +// 1 valid dimension used, with 10 blank ones since it's hard to find a resource with more than 5 dimensions that is feasable to run tests with +import * as cdk from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-cloudwatch-metric-dimensions'); + +const queue = new cdk.CfnResource(stack, 'queue', { type: 'AWS::SQS::Queue' }); + +const numberOfMessagesVisibleMetric = new cloudwatch.Metric({ + namespace: 'AWS/SQS', + metricName: 'ApproximateNumberOfMessagesVisible', + dimensionsMap: { + QueueName: queue.getAtt('QueueName').toString(), + BlankD1: 'value1', + BlankD2: 'value2', + BlankD3: 'value3', + BlankD4: 'value4', + BlankD5: 'value5', + BlankD6: 'value6', + BlankD7: 'value7', + BlankD8: 'value8', + BlankD9: 'value9', + BlankD10: 'value10', + }, +}); + +numberOfMessagesVisibleMetric.createAlarm(stack, 'Alarm', { + threshold: 100, + evaluationPeriods: 3, + datapointsToAlarm: 2, +}); + +new IntegTest(app, 'metric-with-dimensions-test', { + testCases: [stack], +}); \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts index 99f7a27bc138c..8b6c05bc45122 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts @@ -509,8 +509,8 @@ export class Metric implements IMetric { } var dimsArray = Object.keys(dims); - if (dimsArray?.length > 10) { - throw new Error(`The maximum number of dimensions is 10, received ${dimsArray.length}`); + if (dimsArray?.length > 30) { + throw new Error(`The maximum number of dimensions is 30, received ${dimsArray.length}`); } dimsArray.map(key => { diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/metrics.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/metrics.test.ts index ac0d0186ea014..42f3bd14a1fbb 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/metrics.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/metrics.test.ts @@ -112,7 +112,7 @@ describe('Metrics', () => { }); - testDeprecated('throws error when there are more than 10 dimensions', () => { + testDeprecated('throws error when there are more than 30 dimensions', () => { expect(() => { new Metric({ namespace: 'Test', @@ -130,13 +130,33 @@ describe('Metrics', () => { dimensionI: 'value9', dimensionJ: 'value10', dimensionK: 'value11', + dimensionL: 'value12', + dimensionM: 'value13', + dimensionN: 'value14', + dimensionO: 'value15', + dimensionP: 'value16', + dimensionQ: 'value17', + dimensionR: 'value18', + dimensionS: 'value19', + dimensionT: 'value20', + dimensionU: 'value21', + dimensionV: 'value22', + dimensionW: 'value23', + dimensionX: 'value24', + dimensionY: 'value25', + dimensionZ: 'value26', + dimensionAA: 'value27', + dimensionAB: 'value28', + dimensionAC: 'value29', + dimensionAD: 'value30', + dimensionAE: 'value31', }, } ); - }).toThrow(/The maximum number of dimensions is 10, received 11/); + }).toThrow(/The maximum number of dimensions is 30, received 31/); }); - test('throws error when there are more than 10 dimensions in dimensionsMap', () => { + test('throws error when there are more than 30 dimensions in dimensionsMap', () => { expect(() => { new Metric({ namespace: 'Test', @@ -154,9 +174,29 @@ describe('Metrics', () => { dimensionI: 'value9', dimensionJ: 'value10', dimensionK: 'value11', + dimensionL: 'value12', + dimensionM: 'value13', + dimensionN: 'value14', + dimensionO: 'value15', + dimensionP: 'value16', + dimensionQ: 'value17', + dimensionR: 'value18', + dimensionS: 'value19', + dimensionT: 'value20', + dimensionU: 'value21', + dimensionV: 'value22', + dimensionW: 'value23', + dimensionX: 'value24', + dimensionY: 'value25', + dimensionZ: 'value26', + dimensionAA: 'value27', + dimensionAB: 'value28', + dimensionAC: 'value29', + dimensionAD: 'value30', + dimensionAE: 'value31', }, } ); - }).toThrow(/The maximum number of dimensions is 10, received 11/); + }).toThrow(/The maximum number of dimensions is 30, received 31/); });