From 28d1b203370a1b9bb00d429db5675409856838b9 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 22 Jul 2024 00:05:02 +0900 Subject: [PATCH 01/22] feat: add props AlbEcsFargate --- .../lib/base/fargate-service-base.ts | 17 +++++++++++++++++ ...application-load-balanced-fargate-service.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts index d8df18c5501db..25f6367a8493e 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts @@ -89,4 +89,21 @@ export interface FargateServiceBaseProps { * @default - If the property is undefined, `operatingSystemFamily` is LINUX and `cpuArchitecture` is X86_64 */ readonly runtimePlatform?: RuntimePlatform; + + /** + * The minimum number of CPU units to reserve for the container. + * + * @default - No minimum CPU units reserved. + */ + readonly containerCpu?: number; + + /** + * The amount (in MiB) of memory to present to the container. + * + * If your container attempts to exceed the allocated memory, the container + * is terminated. + * + * @default - No memory limit. + */ + readonly containerMemoryLimitMiB?: number; } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 4bc76a56b73dc..6bc4cdea615dc 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -97,6 +97,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc dockerLabels: taskImageOptions.dockerLabels, command: taskImageOptions.command, entryPoint: taskImageOptions.entryPoint, + cpu: props.containerCpu, + memoryLimitMiB: props.containerMemoryLimitMiB, }); container.addPortMappings({ containerPort: taskImageOptions.containerPort || 80, From 971a8632fba5932f46c6c33cb2a0c2b7d23ef7c2 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 22 Jul 2024 00:05:19 +0900 Subject: [PATCH 02/22] test: add unit test --- .../load-balanced-fargate-service.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index 18b6b929f76f6..3c52c26ec189d 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -2066,4 +2066,32 @@ describe('NetworkLoadBalancedFargateService', () => { }, }); }); + + test('specify containerCpu And containerMemoryLimitMiB', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // WHEN + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: 128, + containerMemoryLimitMiB: 256, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + Match.objectLike({ + Cpu: 128, + Memory: 256, + }), + ], + }); + }); }); From e53b7b32500df153b24c94ec2215b66db75550ed Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 22 Jul 2024 00:25:50 +0900 Subject: [PATCH 03/22] test: add integ test --- .../fargate/integ.container-cpu-memory.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts new file mode 100644 index 0000000000000..9f15833cfd49b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts @@ -0,0 +1,27 @@ +import { Vpc } from 'aws-cdk-lib/aws-ec2'; +import { Cluster, ContainerImage } from 'aws-cdk-lib/aws-ecs'; +import { App, Stack } from 'aws-cdk-lib'; +import * as integ from '@aws-cdk/integ-tests-alpha'; +import { ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns'; + +const app = new App(); +const stack = new Stack(app, 'aws-ecs-integ-circuit-breaker-no-dc'); +const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false }); +const cluster = new Cluster(stack, 'Cluster', { vpc }); + +new ApplicationLoadBalancedFargateService(stack, 'myService', { + cluster, + cpu: 256, + memoryLimitMiB: 512, + taskImageOptions: { + image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }, + containerCpu: 128, + containerMemoryLimitMiB: 256, +}); + +new integ.IntegTest(app, 'cpuAndMemoryAreSpecifiedTest', { + testCases: [stack], +}); + +app.synth(); From 78249b6f659616e34344380bb03eb47fecacef54 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 22 Jul 2024 21:49:22 +0900 Subject: [PATCH 04/22] test: add integ test --- ...ecs-integ-container-cpu-memory.assets.json | 19 + ...s-integ-container-cpu-memory.template.json | 782 ++++++++++ .../cdk.out | 1 + ...efaultTestDeployAssert2F87E3D5.assets.json | 19 + ...aultTestDeployAssert2F87E3D5.template.json | 36 + .../integ.json | 12 + .../manifest.json | 341 +++++ .../tree.json | 1338 +++++++++++++++++ .../fargate/integ.container-cpu-memory.ts | 2 +- 9 files changed, 2549 insertions(+), 1 deletion(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/tree.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.assets.json new file mode 100644 index 0000000000000..6810fdc1904fd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "1dc1a7c794acca48436ad02ee22281f5f96bb6899c5d611b68067225a068e5c7": { + "source": { + "path": "aws-ecs-integ-container-cpu-memory.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "1dc1a7c794acca48436ad02ee22281f5f96bb6899c5d611b68067225a068e5c7.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-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.template.json new file mode 100644 index 0000000000000..dc769798706a5 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/aws-ecs-integ-container-cpu-memory.template.json @@ -0,0 +1,782 @@ +{ + "Resources": { + "Vpc8378EB38": { + "Type": "AWS::EC2::VPC", + "Properties": { + "CidrBlock": "10.0.0.0/16", + "EnableDnsHostnames": true, + "EnableDnsSupport": true, + "InstanceTenancy": "default", + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc" + } + ] + } + }, + "VpcPublicSubnet1Subnet5C2D37C4": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.0.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet1RouteTable6C95E38E": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet1RouteTableAssociation97140677": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "VpcPublicSubnet1DefaultRoute3DA9E72A": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "RouteTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet1EIPD7E02669": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ] + } + }, + "VpcPublicSubnet1NATGateway4D7517AA": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet1DefaultRoute3DA9E72A", + "VpcPublicSubnet1RouteTableAssociation97140677" + ] + }, + "VpcPublicSubnet2Subnet691E08A3": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.64.0/18", + "MapPublicIpOnLaunch": true, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Public" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Public" + }, + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet2RouteTable94F7E489": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPublicSubnet2RouteTableAssociationDD5762D8": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "VpcPublicSubnet2DefaultRoute97F91067": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "GatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "RouteTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + } + }, + "DependsOn": [ + "VpcVPCGWBF912B6E" + ] + }, + "VpcPublicSubnet2EIP3C605A87": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc", + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ] + } + }, + "VpcPublicSubnet2NATGateway9182C01D": { + "Type": "AWS::EC2::NatGateway", + "Properties": { + "AllocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" + ] + }, + "SubnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + }, + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ] + }, + "DependsOn": [ + "VpcPublicSubnet2DefaultRoute97F91067", + "VpcPublicSubnet2RouteTableAssociationDD5762D8" + ] + }, + "VpcPrivateSubnet1Subnet536B997A": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.128.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet1RouteTableB2C5B500": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet1RouteTableAssociation70C59FA6": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "VpcPrivateSubnet1DefaultRouteBE02A9ED": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + }, + "RouteTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + } + } + }, + "VpcPrivateSubnet2Subnet3788AAA1": { + "Type": "AWS::EC2::Subnet", + "Properties": { + "AvailabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "CidrBlock": "10.0.192.0/18", + "MapPublicIpOnLaunch": false, + "Tags": [ + { + "Key": "aws-cdk:subnet-name", + "Value": "Private" + }, + { + "Key": "aws-cdk:subnet-type", + "Value": "Private" + }, + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet2RouteTableA678073B": { + "Type": "AWS::EC2::RouteTable", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "VpcPrivateSubnet2RouteTableAssociationA89CAD56": { + "Type": "AWS::EC2::SubnetRouteTableAssociation", + "Properties": { + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "SubnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "VpcPrivateSubnet2DefaultRoute060D2087": { + "Type": "AWS::EC2::Route", + "Properties": { + "DestinationCidrBlock": "0.0.0.0/0", + "NatGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + }, + "RouteTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + } + } + }, + "VpcIGWD7BA715C": { + "Type": "AWS::EC2::InternetGateway", + "Properties": { + "Tags": [ + { + "Key": "Name", + "Value": "aws-ecs-integ-container-cpu-memory/Vpc" + } + ] + } + }, + "VpcVPCGWBF912B6E": { + "Type": "AWS::EC2::VPCGatewayAttachment", + "Properties": { + "InternetGatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "ClusterEB0386A7": { + "Type": "AWS::ECS::Cluster" + }, + "myServiceLB168895E1": { + "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", + "Properties": { + "LoadBalancerAttributes": [ + { + "Key": "deletion_protection.enabled", + "Value": "false" + } + ], + "Scheme": "internet-facing", + "SecurityGroups": [ + { + "Fn::GetAtt": [ + "myServiceLBSecurityGroupFE0ED608", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + ], + "Type": "application" + }, + "DependsOn": [ + "VpcPublicSubnet1DefaultRoute3DA9E72A", + "VpcPublicSubnet1RouteTableAssociation97140677", + "VpcPublicSubnet2DefaultRoute97F91067", + "VpcPublicSubnet2RouteTableAssociationDD5762D8" + ] + }, + "myServiceLBSecurityGroupFE0ED608": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "Automatically created Security Group for ELB awsecsintegcontainercpumemorymyServiceLBBCEAAD1A", + "SecurityGroupIngress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow from anyone on port 80", + "FromPort": 80, + "IpProtocol": "tcp", + "ToPort": 80 + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "myServiceLBSecurityGrouptoawsecsintegcontainercpumemorymyServiceSecurityGroup9341F65E8035B1482A": { + "Type": "AWS::EC2::SecurityGroupEgress", + "Properties": { + "Description": "Load balancer to target", + "DestinationSecurityGroupId": { + "Fn::GetAtt": [ + "myServiceSecurityGroupC3B9D4E0", + "GroupId" + ] + }, + "FromPort": 80, + "GroupId": { + "Fn::GetAtt": [ + "myServiceLBSecurityGroupFE0ED608", + "GroupId" + ] + }, + "IpProtocol": "tcp", + "ToPort": 80 + } + }, + "myServiceLBPublicListenerC78AE8A0": { + "Type": "AWS::ElasticLoadBalancingV2::Listener", + "Properties": { + "DefaultActions": [ + { + "TargetGroupArn": { + "Ref": "myServiceLBPublicListenerECSGroup17E9BBC1" + }, + "Type": "forward" + } + ], + "LoadBalancerArn": { + "Ref": "myServiceLB168895E1" + }, + "Port": 80, + "Protocol": "HTTP" + } + }, + "myServiceLBPublicListenerECSGroup17E9BBC1": { + "Type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "Properties": { + "Port": 80, + "Protocol": "HTTP", + "TargetGroupAttributes": [ + { + "Key": "stickiness.enabled", + "Value": "false" + } + ], + "TargetType": "ip", + "VpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "myServiceTaskDefTaskRole1C1DE6CC": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "myServiceTaskDef7FB8322A": { + "Type": "AWS::ECS::TaskDefinition", + "Properties": { + "ContainerDefinitions": [ + { + "Cpu": 128, + "Essential": true, + "Image": "amazon/amazon-ecs-sample", + "LogConfiguration": { + "LogDriver": "awslogs", + "Options": { + "awslogs-group": { + "Ref": "myServiceTaskDefwebLogGroupA1767F2C" + }, + "awslogs-stream-prefix": "myService", + "awslogs-region": { + "Ref": "AWS::Region" + } + } + }, + "Memory": 256, + "Name": "web", + "PortMappings": [ + { + "ContainerPort": 80, + "Protocol": "tcp" + } + ] + } + ], + "Cpu": "256", + "ExecutionRoleArn": { + "Fn::GetAtt": [ + "myServiceTaskDefExecutionRole618CD311", + "Arn" + ] + }, + "Family": "awsecsintegcontainercpumemorymyServiceTaskDefE8B7A8A9", + "Memory": "512", + "NetworkMode": "awsvpc", + "RequiresCompatibilities": [ + "FARGATE" + ], + "TaskRoleArn": { + "Fn::GetAtt": [ + "myServiceTaskDefTaskRole1C1DE6CC", + "Arn" + ] + } + } + }, + "myServiceTaskDefwebLogGroupA1767F2C": { + "Type": "AWS::Logs::LogGroup", + "UpdateReplacePolicy": "Retain", + "DeletionPolicy": "Retain" + }, + "myServiceTaskDefExecutionRole618CD311": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ecs-tasks.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "myServiceTaskDefExecutionRoleDefaultPolicyBDAEC571": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "myServiceTaskDefwebLogGroupA1767F2C", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "myServiceTaskDefExecutionRoleDefaultPolicyBDAEC571", + "Roles": [ + { + "Ref": "myServiceTaskDefExecutionRole618CD311" + } + ] + } + }, + "myServiceB0B6FAA0": { + "Type": "AWS::ECS::Service", + "Properties": { + "Cluster": { + "Ref": "ClusterEB0386A7" + }, + "DeploymentConfiguration": { + "MaximumPercent": 200, + "MinimumHealthyPercent": 50 + }, + "EnableECSManagedTags": false, + "HealthCheckGracePeriodSeconds": 60, + "LaunchType": "FARGATE", + "LoadBalancers": [ + { + "ContainerName": "web", + "ContainerPort": 80, + "TargetGroupArn": { + "Ref": "myServiceLBPublicListenerECSGroup17E9BBC1" + } + } + ], + "NetworkConfiguration": { + "AwsvpcConfiguration": { + "AssignPublicIp": "DISABLED", + "SecurityGroups": [ + { + "Fn::GetAtt": [ + "myServiceSecurityGroupC3B9D4E0", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + }, + { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + ] + } + }, + "TaskDefinition": { + "Ref": "myServiceTaskDef7FB8322A" + } + }, + "DependsOn": [ + "myServiceLBPublicListenerECSGroup17E9BBC1", + "myServiceLBPublicListenerC78AE8A0", + "myServiceTaskDefTaskRole1C1DE6CC" + ] + }, + "myServiceSecurityGroupC3B9D4E0": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "VpcId": { + "Ref": "Vpc8378EB38" + } + }, + "DependsOn": [ + "myServiceTaskDefTaskRole1C1DE6CC" + ] + }, + "myServiceSecurityGroupfromawsecsintegcontainercpumemorymyServiceLBSecurityGroupB389FFE2807C674A6E": { + "Type": "AWS::EC2::SecurityGroupIngress", + "Properties": { + "Description": "Load balancer to target", + "FromPort": 80, + "GroupId": { + "Fn::GetAtt": [ + "myServiceSecurityGroupC3B9D4E0", + "GroupId" + ] + }, + "IpProtocol": "tcp", + "SourceSecurityGroupId": { + "Fn::GetAtt": [ + "myServiceLBSecurityGroupFE0ED608", + "GroupId" + ] + }, + "ToPort": 80 + }, + "DependsOn": [ + "myServiceTaskDefTaskRole1C1DE6CC" + ] + } + }, + "Outputs": { + "myServiceLoadBalancerDNS3A083E9F": { + "Value": { + "Fn::GetAtt": [ + "myServiceLB168895E1", + "DNSName" + ] + } + }, + "myServiceServiceURL1258C56B": { + "Value": { + "Fn::Join": [ + "", + [ + "http://", + { + "Fn::GetAtt": [ + "myServiceLB168895E1", + "DNSName" + ] + } + ] + ] + } + } + }, + "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-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.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-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets.json new file mode 100644 index 0000000000000..f7eb1da7d09a6 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.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-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.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-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/integ.json new file mode 100644 index 0000000000000..f368a027cacce --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "cpuAndMemoryAreSpecifiedTest/DefaultTest": { + "stacks": [ + "aws-ecs-integ-container-cpu-memory" + ], + "assertionStack": "cpuAndMemoryAreSpecifiedTest/DefaultTest/DeployAssert", + "assertionStackName": "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/manifest.json new file mode 100644 index 0000000000000..ae618a37494b4 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/manifest.json @@ -0,0 +1,341 @@ +{ + "version": "36.0.0", + "artifacts": { + "aws-ecs-integ-container-cpu-memory.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "aws-ecs-integ-container-cpu-memory.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "aws-ecs-integ-container-cpu-memory": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "aws-ecs-integ-container-cpu-memory.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}/1dc1a7c794acca48436ad02ee22281f5f96bb6899c5d611b68067225a068e5c7.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "aws-ecs-integ-container-cpu-memory.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-ecs-integ-container-cpu-memory.assets" + ], + "metadata": { + "/aws-ecs-integ-container-cpu-memory/Vpc/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Vpc8378EB38" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1Subnet5C2D37C4" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1RouteTable6C95E38E" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1RouteTableAssociation97140677" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1DefaultRoute3DA9E72A" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1EIPD7E02669" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet1NATGateway4D7517AA" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2Subnet691E08A3" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2RouteTable94F7E489" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2RouteTableAssociationDD5762D8" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2DefaultRoute97F91067" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/EIP": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2EIP3C605A87" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/NATGateway": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPublicSubnet2NATGateway9182C01D" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1Subnet536B997A" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1RouteTableB2C5B500" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1RouteTableAssociation70C59FA6" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet1DefaultRouteBE02A9ED" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/Subnet": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2Subnet3788AAA1" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/RouteTable": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2RouteTableA678073B" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/RouteTableAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2RouteTableAssociationA89CAD56" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/DefaultRoute": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcPrivateSubnet2DefaultRoute060D2087" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/IGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcIGWD7BA715C" + } + ], + "/aws-ecs-integ-container-cpu-memory/Vpc/VPCGW": [ + { + "type": "aws:cdk:logicalId", + "data": "VpcVPCGWBF912B6E" + } + ], + "/aws-ecs-integ-container-cpu-memory/Cluster/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "ClusterEB0386A7" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/LB/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceLB168895E1" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/LB/SecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceLBSecurityGroupFE0ED608" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/LB/SecurityGroup/to awsecsintegcontainercpumemorymyServiceSecurityGroup9341F65E:80": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceLBSecurityGrouptoawsecsintegcontainercpumemorymyServiceSecurityGroup9341F65E8035B1482A" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/LB/PublicListener/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceLBPublicListenerC78AE8A0" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/LB/PublicListener/ECSGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceLBPublicListenerECSGroup17E9BBC1" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/LoadBalancerDNS": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceLoadBalancerDNS3A083E9F" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/ServiceURL": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceServiceURL1258C56B" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/TaskDef/TaskRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceTaskDefTaskRole1C1DE6CC" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/TaskDef/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceTaskDef7FB8322A" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/TaskDef/web/LogGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceTaskDefwebLogGroupA1767F2C" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/TaskDef/ExecutionRole/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceTaskDefExecutionRole618CD311" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/TaskDef/ExecutionRole/DefaultPolicy/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceTaskDefExecutionRoleDefaultPolicyBDAEC571" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/Service/Service": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceB0B6FAA0" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceSecurityGroupC3B9D4E0" + } + ], + "/aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup/from awsecsintegcontainercpumemorymyServiceLBSecurityGroupB389FFE2:80": [ + { + "type": "aws:cdk:logicalId", + "data": "myServiceSecurityGroupfromawsecsintegcontainercpumemorymyServiceLBSecurityGroupB389FFE2807C674A6E" + } + ], + "/aws-ecs-integ-container-cpu-memory/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/aws-ecs-integ-container-cpu-memory/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "aws-ecs-integ-container-cpu-memory" + }, + "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.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": [ + "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.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": [ + "cpuAndMemoryAreSpecifiedTestDefaultTestDeployAssert2F87E3D5.assets" + ], + "metadata": { + "/cpuAndMemoryAreSpecifiedTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cpuAndMemoryAreSpecifiedTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cpuAndMemoryAreSpecifiedTest/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-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/tree.json new file mode 100644 index 0000000000000..e3f61d8edf233 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.js.snapshot/tree.json @@ -0,0 +1,1338 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "aws-ecs-integ-container-cpu-memory": { + "id": "aws-ecs-integ-container-cpu-memory", + "path": "aws-ecs-integ-container-cpu-memory", + "children": { + "Vpc": { + "id": "Vpc", + "path": "aws-ecs-integ-container-cpu-memory/Vpc", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPC", + "aws:cdk:cloudformation:props": { + "cidrBlock": "10.0.0.0/16", + "enableDnsHostnames": true, + "enableDnsSupport": true, + "instanceTenancy": "default", + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "PublicSubnet1": { + "id": "PublicSubnet1", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.0.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/Acl", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + }, + "subnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "routeTableId": { + "Ref": "VpcPublicSubnet1RouteTable6C95E38E" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet1EIPD7E02669", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet1" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "PublicSubnet2": { + "id": "PublicSubnet2", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.64.0/18", + "mapPublicIpOnLaunch": true, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Public" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Public" + }, + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/Acl", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + }, + "subnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "gatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "routeTableId": { + "Ref": "VpcPublicSubnet2RouteTable94F7E489" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "EIP": { + "id": "EIP", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/EIP", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::EIP", + "aws:cdk:cloudformation:props": { + "domain": "vpc", + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "NATGateway": { + "id": "NATGateway", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2/NATGateway", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::NatGateway", + "aws:cdk:cloudformation:props": { + "allocationId": { + "Fn::GetAtt": [ + "VpcPublicSubnet2EIP3C605A87", + "AllocationId" + ] + }, + "subnetId": { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + }, + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PublicSubnet2" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "PrivateSubnet1": { + "id": "PrivateSubnet1", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 0, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.128.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/Acl", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet1/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet1NATGateway4D7517AA" + }, + "routeTableId": { + "Ref": "VpcPrivateSubnet1RouteTableB2C5B500" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "PrivateSubnet2": { + "id": "PrivateSubnet2", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2", + "children": { + "Subnet": { + "id": "Subnet", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/Subnet", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Subnet", + "aws:cdk:cloudformation:props": { + "availabilityZone": { + "Fn::Select": [ + 1, + { + "Fn::GetAZs": "" + } + ] + }, + "cidrBlock": "10.0.192.0/18", + "mapPublicIpOnLaunch": false, + "tags": [ + { + "key": "aws-cdk:subnet-name", + "value": "Private" + }, + { + "key": "aws-cdk:subnet-type", + "value": "Private" + }, + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Acl": { + "id": "Acl", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/Acl", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTable": { + "id": "RouteTable", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/RouteTable", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::RouteTable", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "RouteTableAssociation": { + "id": "RouteTableAssociation", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/RouteTableAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SubnetRouteTableAssociation", + "aws:cdk:cloudformation:props": { + "routeTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + }, + "subnetId": { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DefaultRoute": { + "id": "DefaultRoute", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/PrivateSubnet2/DefaultRoute", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::Route", + "aws:cdk:cloudformation:props": { + "destinationCidrBlock": "0.0.0.0/0", + "natGatewayId": { + "Ref": "VpcPublicSubnet2NATGateway9182C01D" + }, + "routeTableId": { + "Ref": "VpcPrivateSubnet2RouteTableA678073B" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "IGW": { + "id": "IGW", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/IGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::InternetGateway", + "aws:cdk:cloudformation:props": { + "tags": [ + { + "key": "Name", + "value": "aws-ecs-integ-container-cpu-memory/Vpc" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "VPCGW": { + "id": "VPCGW", + "path": "aws-ecs-integ-container-cpu-memory/Vpc/VPCGW", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::VPCGatewayAttachment", + "aws:cdk:cloudformation:props": { + "internetGatewayId": { + "Ref": "VpcIGWD7BA715C" + }, + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Cluster": { + "id": "Cluster", + "path": "aws-ecs-integ-container-cpu-memory/Cluster", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/Cluster/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::Cluster", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "myService": { + "id": "myService", + "path": "aws-ecs-integ-container-cpu-memory/myService", + "children": { + "LB": { + "id": "LB", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::LoadBalancer", + "aws:cdk:cloudformation:props": { + "loadBalancerAttributes": [ + { + "key": "deletion_protection.enabled", + "value": "false" + } + ], + "scheme": "internet-facing", + "securityGroups": [ + { + "Fn::GetAtt": [ + "myServiceLBSecurityGroupFE0ED608", + "GroupId" + ] + } + ], + "subnets": [ + { + "Ref": "VpcPublicSubnet1Subnet5C2D37C4" + }, + { + "Ref": "VpcPublicSubnet2Subnet691E08A3" + } + ], + "type": "application" + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "SecurityGroup": { + "id": "SecurityGroup", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "Automatically created Security Group for ELB awsecsintegcontainercpumemorymyServiceLBBCEAAD1A", + "securityGroupIngress": [ + { + "cidrIp": "0.0.0.0/0", + "ipProtocol": "tcp", + "fromPort": 80, + "toPort": 80, + "description": "Allow from anyone on port 80" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "to awsecsintegcontainercpumemorymyServiceSecurityGroup9341F65E:80": { + "id": "to awsecsintegcontainercpumemorymyServiceSecurityGroup9341F65E:80", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/SecurityGroup/to awsecsintegcontainercpumemorymyServiceSecurityGroup9341F65E:80", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroupEgress", + "aws:cdk:cloudformation:props": { + "description": "Load balancer to target", + "destinationSecurityGroupId": { + "Fn::GetAtt": [ + "myServiceSecurityGroupC3B9D4E0", + "GroupId" + ] + }, + "fromPort": 80, + "groupId": { + "Fn::GetAtt": [ + "myServiceLBSecurityGroupFE0ED608", + "GroupId" + ] + }, + "ipProtocol": "tcp", + "toPort": 80 + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "PublicListener": { + "id": "PublicListener", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/PublicListener", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/PublicListener/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::Listener", + "aws:cdk:cloudformation:props": { + "defaultActions": [ + { + "type": "forward", + "targetGroupArn": { + "Ref": "myServiceLBPublicListenerECSGroup17E9BBC1" + } + } + ], + "loadBalancerArn": { + "Ref": "myServiceLB168895E1" + }, + "port": 80, + "protocol": "HTTP" + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "ECSGroup": { + "id": "ECSGroup", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/PublicListener/ECSGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/LB/PublicListener/ECSGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ElasticLoadBalancingV2::TargetGroup", + "aws:cdk:cloudformation:props": { + "port": 80, + "protocol": "HTTP", + "targetGroupAttributes": [ + { + "key": "stickiness.enabled", + "value": "false" + } + ], + "targetType": "ip", + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "LoadBalancerDNS": { + "id": "LoadBalancerDNS", + "path": "aws-ecs-integ-container-cpu-memory/myService/LoadBalancerDNS", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "ServiceURL": { + "id": "ServiceURL", + "path": "aws-ecs-integ-container-cpu-memory/myService/ServiceURL", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "TaskDef": { + "id": "TaskDef", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef", + "children": { + "TaskRole": { + "id": "TaskRole", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/TaskRole", + "children": { + "ImportTaskRole": { + "id": "ImportTaskRole", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/TaskRole/ImportTaskRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/TaskRole/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" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::TaskDefinition", + "aws:cdk:cloudformation:props": { + "containerDefinitions": [ + { + "cpu": 128, + "essential": true, + "image": "amazon/amazon-ecs-sample", + "memory": 256, + "name": "web", + "portMappings": [ + { + "containerPort": 80, + "protocol": "tcp" + } + ], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": { + "Ref": "myServiceTaskDefwebLogGroupA1767F2C" + }, + "awslogs-stream-prefix": "myService", + "awslogs-region": { + "Ref": "AWS::Region" + } + } + } + } + ], + "cpu": "256", + "executionRoleArn": { + "Fn::GetAtt": [ + "myServiceTaskDefExecutionRole618CD311", + "Arn" + ] + }, + "family": "awsecsintegcontainercpumemorymyServiceTaskDefE8B7A8A9", + "memory": "512", + "networkMode": "awsvpc", + "requiresCompatibilities": [ + "FARGATE" + ], + "taskRoleArn": { + "Fn::GetAtt": [ + "myServiceTaskDefTaskRole1C1DE6CC", + "Arn" + ] + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "web": { + "id": "web", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/web", + "children": { + "LogGroup": { + "id": "LogGroup", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/web/LogGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/web/LogGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Logs::LogGroup", + "aws:cdk:cloudformation:props": {} + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "ExecutionRole": { + "id": "ExecutionRole", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/ExecutionRole", + "children": { + "ImportExecutionRole": { + "id": "ImportExecutionRole", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/ExecutionRole/ImportExecutionRole", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/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": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/ExecutionRole/DefaultPolicy", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/TaskDef/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::GetAtt": [ + "myServiceTaskDefwebLogGroupA1767F2C", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "policyName": "myServiceTaskDefExecutionRoleDefaultPolicyBDAEC571", + "roles": [ + { + "Ref": "myServiceTaskDefExecutionRole618CD311" + } + ] + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Service": { + "id": "Service", + "path": "aws-ecs-integ-container-cpu-memory/myService/Service", + "children": { + "Service": { + "id": "Service", + "path": "aws-ecs-integ-container-cpu-memory/myService/Service/Service", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ECS::Service", + "aws:cdk:cloudformation:props": { + "cluster": { + "Ref": "ClusterEB0386A7" + }, + "deploymentConfiguration": { + "maximumPercent": 200, + "minimumHealthyPercent": 50 + }, + "enableEcsManagedTags": false, + "healthCheckGracePeriodSeconds": 60, + "launchType": "FARGATE", + "loadBalancers": [ + { + "targetGroupArn": { + "Ref": "myServiceLBPublicListenerECSGroup17E9BBC1" + }, + "containerName": "web", + "containerPort": 80 + } + ], + "networkConfiguration": { + "awsvpcConfiguration": { + "assignPublicIp": "DISABLED", + "subnets": [ + { + "Ref": "VpcPrivateSubnet1Subnet536B997A" + }, + { + "Ref": "VpcPrivateSubnet2Subnet3788AAA1" + } + ], + "securityGroups": [ + { + "Fn::GetAtt": [ + "myServiceSecurityGroupC3B9D4E0", + "GroupId" + ] + } + ] + } + }, + "taskDefinition": { + "Ref": "myServiceTaskDef7FB8322A" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "SecurityGroup": { + "id": "SecurityGroup", + "path": "aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "vpcId": { + "Ref": "Vpc8378EB38" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "from awsecsintegcontainercpumemorymyServiceLBSecurityGroupB389FFE2:80": { + "id": "from awsecsintegcontainercpumemorymyServiceLBSecurityGroupB389FFE2:80", + "path": "aws-ecs-integ-container-cpu-memory/myService/Service/SecurityGroup/from awsecsintegcontainercpumemorymyServiceLBSecurityGroupB389FFE2:80", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroupIngress", + "aws:cdk:cloudformation:props": { + "description": "Load balancer to target", + "fromPort": 80, + "groupId": { + "Fn::GetAtt": [ + "myServiceSecurityGroupC3B9D4E0", + "GroupId" + ] + }, + "ipProtocol": "tcp", + "sourceSecurityGroupId": { + "Fn::GetAtt": [ + "myServiceLBSecurityGroupFE0ED608", + "GroupId" + ] + }, + "toPort": 80 + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "aws-ecs-integ-container-cpu-memory/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "aws-ecs-integ-container-cpu-memory/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "cpuAndMemoryAreSpecifiedTest": { + "id": "cpuAndMemoryAreSpecifiedTest", + "path": "cpuAndMemoryAreSpecifiedTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "cpuAndMemoryAreSpecifiedTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "cpuAndMemoryAreSpecifiedTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "cpuAndMemoryAreSpecifiedTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cpuAndMemoryAreSpecifiedTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cpuAndMemoryAreSpecifiedTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.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": "constructs.Construct", + "version": "10.3.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts index 9f15833cfd49b..251ff86d24752 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.container-cpu-memory.ts @@ -5,7 +5,7 @@ import * as integ from '@aws-cdk/integ-tests-alpha'; import { ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns'; const app = new App(); -const stack = new Stack(app, 'aws-ecs-integ-circuit-breaker-no-dc'); +const stack = new Stack(app, 'aws-ecs-integ-container-cpu-memory'); const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false }); const cluster = new Cluster(stack, 'Cluster', { vpc }); From 72fcbf4fbc500bbdc8d2f48130c6684ebcf2092b Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 22 Jul 2024 21:49:42 +0900 Subject: [PATCH 05/22] docs: update README --- packages/aws-cdk-lib/aws-ecs-patterns/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/README.md b/packages/aws-cdk-lib/aws-ecs-patterns/README.md index 964324b8b4959..c50ee9822f428 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/README.md +++ b/packages/aws-cdk-lib/aws-ecs-patterns/README.md @@ -70,6 +70,10 @@ By setting `redirectHTTP` to true, CDK will automatically create a listener on p If you specify the option `recordType` you can decide if you want the construct to use CNAME or Route53-Aliases as record sets. +If you specify the option `containerCpu` allows you to set the minimum number of CPU units to reserve for the container. + +If you specify the option `containerMemoryLimitMiB` allows you to set the amount of memory (in MiB) to provide to the container. + If you need to encrypt the traffic between the load balancer and the ECS tasks, you can set the `targetProtocol` to `HTTPS`. Additionally, if more than one application target group are needed, instantiate one of the following: From 56791bdbf47e5fedf89d2c61b8f061c3496e1677 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 22 Jul 2024 22:30:38 +0900 Subject: [PATCH 06/22] feat: Fixed how to specify props --- .../lib/base/fargate-service-base.ts | 17 ----------------- ...application-load-balanced-fargate-service.ts | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts index 25f6367a8493e..d8df18c5501db 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/base/fargate-service-base.ts @@ -89,21 +89,4 @@ export interface FargateServiceBaseProps { * @default - If the property is undefined, `operatingSystemFamily` is LINUX and `cpuArchitecture` is X86_64 */ readonly runtimePlatform?: RuntimePlatform; - - /** - * The minimum number of CPU units to reserve for the container. - * - * @default - No minimum CPU units reserved. - */ - readonly containerCpu?: number; - - /** - * The amount (in MiB) of memory to present to the container. - * - * If your container attempts to exceed the allocated memory, the container - * is terminated. - * - * @default - No memory limit. - */ - readonly containerMemoryLimitMiB?: number; } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 6bc4cdea615dc..8a5fcbe4baab2 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -36,6 +36,23 @@ export interface ApplicationLoadBalancedFargateServiceProps extends ApplicationL * @default - Health check configuration from container. */ readonly healthCheck?: HealthCheck; + + /** + * The minimum number of CPU units to reserve for the container. + * + * @default - No minimum CPU units reserved. + */ + readonly containerCpu?: number; + + /** + * The amount (in MiB) of memory to present to the container. + * + * If your container attempts to exceed the allocated memory, the container + * is terminated. + * + * @default - No memory limit. + */ + readonly containerMemoryLimitMiB?: number; } /** From a2f826003c425212b08b69ace73f5877077c2584 Mon Sep 17 00:00:00 2001 From: Ren Yamanashi <96362223+ren-yamanashi@users.noreply.github.com> Date: Thu, 25 Jul 2024 20:02:40 +0900 Subject: [PATCH 07/22] Update packages/aws-cdk-lib/aws-ecs-patterns/README.md Co-authored-by: Kenta Goto (k.goto) <24818752+go-to-k@users.noreply.github.com> --- packages/aws-cdk-lib/aws-ecs-patterns/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/README.md b/packages/aws-cdk-lib/aws-ecs-patterns/README.md index c50ee9822f428..14875a46cc665 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/README.md +++ b/packages/aws-cdk-lib/aws-ecs-patterns/README.md @@ -70,9 +70,9 @@ By setting `redirectHTTP` to true, CDK will automatically create a listener on p If you specify the option `recordType` you can decide if you want the construct to use CNAME or Route53-Aliases as record sets. -If you specify the option `containerCpu` allows you to set the minimum number of CPU units to reserve for the container. +To set the minimum number of CPU units to reserve for the container, you can use the `containerCpu` property. -If you specify the option `containerMemoryLimitMiB` allows you to set the amount of memory (in MiB) to provide to the container. +To set the amount of memory (in MiB) to provide to the container, you can use the `containerMemoryLimitMiB` property. If you need to encrypt the traffic between the load balancer and the ECS tasks, you can set the `targetProtocol` to `HTTPS`. From 59b2aa1fe39180ed22d597c26e07c881f1c6f610 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Thu, 25 Jul 2024 20:12:25 +0900 Subject: [PATCH 08/22] test: Move test to describe of ApplicationLoadBalancedFargateService --- .../load-balanced-fargate-service.test.ts | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index 3c52c26ec189d..21b3ae28b0259 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1433,6 +1433,34 @@ describe('ApplicationLoadBalancedFargateService', () => { }, }); }); + + test('specify containerCpu and containerMemoryLimitMiB', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // WHEN + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: 128, + containerMemoryLimitMiB: 256, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + Match.objectLike({ + Cpu: 128, + Memory: 256, + }), + ], + }); + }); }); describe('NetworkLoadBalancedFargateService', () => { @@ -2066,32 +2094,4 @@ describe('NetworkLoadBalancedFargateService', () => { }, }); }); - - test('specify containerCpu And containerMemoryLimitMiB', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.Vpc(stack, 'VPC'); - const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); - - // WHEN - new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { - cluster, - taskImageOptions: { - image: ecs.ContainerImage.fromRegistry('test'), - }, - loadBalancerName: 'alb-test-load-balancer', - containerCpu: 128, - containerMemoryLimitMiB: 256, - }); - - // THEN - Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { - ContainerDefinitions: [ - Match.objectLike({ - Cpu: 128, - Memory: 256, - }), - ], - }); - }); }); From 3f2f3daf007ec28077913a9ca3f76b20b9b09480 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Thu, 25 Jul 2024 20:18:48 +0900 Subject: [PATCH 09/22] docs: add properties --- packages/aws-cdk-lib/aws-ecs-patterns/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/README.md b/packages/aws-cdk-lib/aws-ecs-patterns/README.md index 14875a46cc665..41425594daa19 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/README.md +++ b/packages/aws-cdk-lib/aws-ecs-patterns/README.md @@ -46,6 +46,8 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat command: ['command'], entryPoint: ['entry', 'point'], }, + containerCpu: 256, + containerMemoryLimitMiB: 512, }); loadBalancedFargateService.targetGroup.configureHealthCheck({ From a32ddc3b0ca685dae09f052b7ddeb28af12419d6 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Sat, 3 Aug 2024 12:27:55 +0900 Subject: [PATCH 10/22] feat: validate containerCpu and containerMemory --- ...plication-load-balanced-fargate-service.ts | 37 ++++++ .../load-balanced-fargate-service.test.ts | 124 ++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 8a5fcbe4baab2..153b917c260ba 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -87,6 +87,9 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } else if (props.taskDefinition) { this.taskDefinition = props.taskDefinition; } else if (props.taskImageOptions) { + this.validateContainerCpu(props.containerCpu, props.cpu); + this.validateContainerMemoryLimitMiB(props.containerMemoryLimitMiB, props.memoryLimitMiB); + const taskImageOptions = props.taskImageOptions; this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { memoryLimitMiB: props.memoryLimitMiB, @@ -171,4 +174,38 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc throw new Error(`${name}: Must be a non-negative integer; received ${value}`); } } + + /** + * Throws an error if containerCpu is greater than cpu or is a positive integer. + * @param containerCpu The minimum number of CPU units to reserve for the container. + * @param cpu The number of cpu units used by the task. (default: 256) + */ + private validateContainerCpu(containerCpu?: number, cpu: number = 256) { + if (!containerCpu || Token.isUnresolved(containerCpu) || Token.isUnresolved(cpu)) { + return; + } + if (containerCpu > cpu) { + throw new Error('containerCpu must be less than to cpu'); + } + if (containerCpu < 0 || !Number.isInteger(containerCpu)) { + throw new Error('containerCpu must be a non-negative integer'); + } + } + + /** + * Throws an error if containerMemoryLimitMiB is greater than memoryLimitMiB or is a positive integer. + * @param containerMemoryLimitMiB The amount (in MiB) of memory to present to the container. + * @param memoryLimitMiB The amount (in MiB) of memory used by the task. (default: 512) + */ + private validateContainerMemoryLimitMiB(containerMemoryLimitMiB?: number, memoryLimitMiB: number = 512) { + if (!containerMemoryLimitMiB || Token.isUnresolved(containerMemoryLimitMiB) || Token.isUnresolved(memoryLimitMiB)) { + return; + } + if (containerMemoryLimitMiB > memoryLimitMiB) { + throw new Error('containerMemoryLimitMiB must be less than to memoryLimitMiB'); + } + if (containerMemoryLimitMiB < 0 || !Number.isInteger(containerMemoryLimitMiB)) { + throw new Error('containerMemoryLimitMiB must be a non-negative integer'); + } + } } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index b0a3f17a5ef86..be002e5a9d7bf 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1461,6 +1461,130 @@ describe('ApplicationLoadBalancedFargateService', () => { ], }); }); + + test('errors when containerCpu is less than cpu', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + cpu: 256, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: 512, + }); + }).toThrow('containerCpu must be less than to cpu'); + }); + + describe('errors when containerCpu is non-negative integer', () => { + test('when containerCpu is negative integer', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + cpu: 256, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: -1, + }); + }).toThrow('containerCpu must be a non-negative integer'); + }); + + test('when containerCpu is float', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + cpu: 256, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: 0.5, + }); + }).toThrow('containerCpu must be a non-negative integer'); + }); + }); + + test('errors when containerMemoryLimitMiB is less than memoryLimitMiB', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + memoryLimitMiB: 256, + loadBalancerName: 'alb-test-load-balancer', + containerMemoryLimitMiB: 512, + }); + }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB'); + }); + + describe('errors when containerMemoryLimitMiB is non-negative integer', () => { + test('when containerMemoryLimitMiB is negative integer', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + memoryLimitMiB: 256, + loadBalancerName: 'alb-test-load-balancer', + containerMemoryLimitMiB: -1, + }); + }).toThrow('containerMemoryLimitMiB must be a non-negative integer'); + }); + + test('when containerMemoryLimitMiB is float', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + memoryLimitMiB: 256, + loadBalancerName: 'alb-test-load-balancer', + containerMemoryLimitMiB: 0.5, + }); + }).toThrow('containerMemoryLimitMiB must be a non-negative integer'); + }); + }); }); describe('NetworkLoadBalancedFargateService', () => { From 3f8cfcbdae87cae0bd6fca994a13638651b01fee Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Sat, 3 Aug 2024 12:42:26 +0900 Subject: [PATCH 11/22] test: update test description --- .../test/fargate/load-balanced-fargate-service.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index be002e5a9d7bf..bf253f9b5f530 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1462,7 +1462,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }); }); - test('errors when containerCpu is less than cpu', () => { + test('errors when containerCpu is larger than cpu', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -1482,7 +1482,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }).toThrow('containerCpu must be less than to cpu'); }); - describe('errors when containerCpu is non-negative integer', () => { + describe('errors when containerCpu is positive integer', () => { test('when containerCpu is negative integer', () => { // GIVEN const stack = new cdk.Stack(); @@ -1524,7 +1524,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }); }); - test('errors when containerMemoryLimitMiB is less than memoryLimitMiB', () => { + test('errors when containerMemoryLimitMiB is larger than memoryLimitMiB', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -1544,7 +1544,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB'); }); - describe('errors when containerMemoryLimitMiB is non-negative integer', () => { + describe('errors when containerMemoryLimitMiB is positive integer', () => { test('when containerMemoryLimitMiB is negative integer', () => { // GIVEN const stack = new cdk.Stack(); From 7ad155ded06bcb5b5ea7068ab217b93e0f2c258b Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Sat, 3 Aug 2024 12:51:25 +0900 Subject: [PATCH 12/22] feat: validate containerCpu and containerMemory --- .../application-load-balanced-fargate-service.ts | 8 ++++---- .../load-balanced-fargate-service.test.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 153b917c260ba..48d08f4ff23da 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -176,7 +176,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } /** - * Throws an error if containerCpu is greater than cpu or is a positive integer. + * Throws an error if containerCpu is greater than cpu or is a not positive integer. * @param containerCpu The minimum number of CPU units to reserve for the container. * @param cpu The number of cpu units used by the task. (default: 256) */ @@ -188,12 +188,12 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc throw new Error('containerCpu must be less than to cpu'); } if (containerCpu < 0 || !Number.isInteger(containerCpu)) { - throw new Error('containerCpu must be a non-negative integer'); + throw new Error('containerCpu must be positive integer'); } } /** - * Throws an error if containerMemoryLimitMiB is greater than memoryLimitMiB or is a positive integer. + * Throws an error if containerMemoryLimitMiB is greater than memoryLimitMiB or is a not positive integer. * @param containerMemoryLimitMiB The amount (in MiB) of memory to present to the container. * @param memoryLimitMiB The amount (in MiB) of memory used by the task. (default: 512) */ @@ -205,7 +205,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc throw new Error('containerMemoryLimitMiB must be less than to memoryLimitMiB'); } if (containerMemoryLimitMiB < 0 || !Number.isInteger(containerMemoryLimitMiB)) { - throw new Error('containerMemoryLimitMiB must be a non-negative integer'); + throw new Error('containerMemoryLimitMiB must be positive integer'); } } } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index bf253f9b5f530..cf1f2d02ad3ee 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1462,7 +1462,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }); }); - test('errors when containerCpu is larger than cpu', () => { + test('errors when containerCpu is greater than cpu', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -1482,7 +1482,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }).toThrow('containerCpu must be less than to cpu'); }); - describe('errors when containerCpu is positive integer', () => { + describe('errors when containerCpu is not positive integer', () => { test('when containerCpu is negative integer', () => { // GIVEN const stack = new cdk.Stack(); @@ -1500,7 +1500,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: -1, }); - }).toThrow('containerCpu must be a non-negative integer'); + }).toThrow('containerCpu must be positive integer'); }); test('when containerCpu is float', () => { @@ -1520,11 +1520,11 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 0.5, }); - }).toThrow('containerCpu must be a non-negative integer'); + }).toThrow('containerCpu must be positive integer'); }); }); - test('errors when containerMemoryLimitMiB is larger than memoryLimitMiB', () => { + test('errors when containerMemoryLimitMiB is greater than memoryLimitMiB', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -1544,7 +1544,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB'); }); - describe('errors when containerMemoryLimitMiB is positive integer', () => { + describe('errors when containerMemoryLimitMiB is not positive integer', () => { test('when containerMemoryLimitMiB is negative integer', () => { // GIVEN const stack = new cdk.Stack(); @@ -1562,7 +1562,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: -1, }); - }).toThrow('containerMemoryLimitMiB must be a non-negative integer'); + }).toThrow('containerMemoryLimitMiB must be positive integer'); }); test('when containerMemoryLimitMiB is float', () => { @@ -1582,7 +1582,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 0.5, }); - }).toThrow('containerMemoryLimitMiB must be a non-negative integer'); + }).toThrow('containerMemoryLimitMiB must be positive integer'); }); }); }); From d8dd23402046db94d12bb9d392935c4834d2a7a3 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Sat, 3 Aug 2024 13:11:23 +0900 Subject: [PATCH 13/22] feat: validate containerCpu and containerMemory --- ...plication-load-balanced-fargate-service.ts | 41 +++++-------------- .../load-balanced-fargate-service.test.ts | 12 +++--- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 48d08f4ff23da..1271838ac8935 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -87,8 +87,11 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } else if (props.taskDefinition) { this.taskDefinition = props.taskDefinition; } else if (props.taskImageOptions) { - this.validateContainerCpu(props.containerCpu, props.cpu); - this.validateContainerMemoryLimitMiB(props.containerMemoryLimitMiB, props.memoryLimitMiB); + this.validateHealthyPercentage('containerCpu', props.containerCpu); + this.validateHealthyPercentage('containerMemoryLimitMiB', props.containerMemoryLimitMiB); + + this.validateNotExceeding('containerCpu', props.cpu ?? 256, props.containerCpu); + this.validateNotExceeding('containerMemoryLimitMiB', props.memoryLimitMiB ?? 512, props.containerMemoryLimitMiB); const taskImageOptions = props.taskImageOptions; this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { @@ -176,36 +179,12 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } /** - * Throws an error if containerCpu is greater than cpu or is a not positive integer. - * @param containerCpu The minimum number of CPU units to reserve for the container. - * @param cpu The number of cpu units used by the task. (default: 256) + * Throws an error if the specified value is greater than the limit. */ - private validateContainerCpu(containerCpu?: number, cpu: number = 256) { - if (!containerCpu || Token.isUnresolved(containerCpu) || Token.isUnresolved(cpu)) { - return; - } - if (containerCpu > cpu) { - throw new Error('containerCpu must be less than to cpu'); - } - if (containerCpu < 0 || !Number.isInteger(containerCpu)) { - throw new Error('containerCpu must be positive integer'); - } - } - - /** - * Throws an error if containerMemoryLimitMiB is greater than memoryLimitMiB or is a not positive integer. - * @param containerMemoryLimitMiB The amount (in MiB) of memory to present to the container. - * @param memoryLimitMiB The amount (in MiB) of memory used by the task. (default: 512) - */ - private validateContainerMemoryLimitMiB(containerMemoryLimitMiB?: number, memoryLimitMiB: number = 512) { - if (!containerMemoryLimitMiB || Token.isUnresolved(containerMemoryLimitMiB) || Token.isUnresolved(memoryLimitMiB)) { - return; - } - if (containerMemoryLimitMiB > memoryLimitMiB) { - throw new Error('containerMemoryLimitMiB must be less than to memoryLimitMiB'); - } - if (containerMemoryLimitMiB < 0 || !Number.isInteger(containerMemoryLimitMiB)) { - throw new Error('containerMemoryLimitMiB must be positive integer'); + private validateNotExceeding(name: string, limit: number, value?: number) { + if (value === undefined || Token.isUnresolved(value)) { return; } + if (value > limit) { + throw new Error(`${name}: Must be less than or equal to ${limit}; received ${value}`); } } } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index cf1f2d02ad3ee..06eb6acc83909 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1479,7 +1479,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 512, }); - }).toThrow('containerCpu must be less than to cpu'); + }).toThrow('containerCpu: Must be less than or equal to 256; received 512'); }); describe('errors when containerCpu is not positive integer', () => { @@ -1500,7 +1500,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: -1, }); - }).toThrow('containerCpu must be positive integer'); + }).toThrow('containerCpu: Must be a non-negative integer; received -1'); }); test('when containerCpu is float', () => { @@ -1520,7 +1520,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 0.5, }); - }).toThrow('containerCpu must be positive integer'); + }).toThrow('containerCpu: Must be a non-negative integer; received 0.5'); }); }); @@ -1541,7 +1541,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 512, }); - }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB'); + }).toThrow('containerMemoryLimitMiB: Must be less than or equal to 256; received 512'); }); describe('errors when containerMemoryLimitMiB is not positive integer', () => { @@ -1562,7 +1562,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: -1, }); - }).toThrow('containerMemoryLimitMiB must be positive integer'); + }).toThrow('containerMemoryLimitMiB: Must be a non-negative integer; received -1'); }); test('when containerMemoryLimitMiB is float', () => { @@ -1582,7 +1582,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 0.5, }); - }).toThrow('containerMemoryLimitMiB must be positive integer'); + }).toThrow('containerMemoryLimitMiB: Must be a non-negative integer; received 0.5'); }); }); }); From ef494bd1fe8f15fcb4d5d60e4b804cdfc8123366 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Mon, 5 Aug 2024 21:47:01 +0900 Subject: [PATCH 14/22] feat: validate containerCpu and containerMemory --- ...plication-load-balanced-fargate-service.ts | 41 ++++++++++++++----- .../load-balanced-fargate-service.test.ts | 12 +++--- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 1271838ac8935..46128e4e6104d 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -87,11 +87,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } else if (props.taskDefinition) { this.taskDefinition = props.taskDefinition; } else if (props.taskImageOptions) { - this.validateHealthyPercentage('containerCpu', props.containerCpu); - this.validateHealthyPercentage('containerMemoryLimitMiB', props.containerMemoryLimitMiB); - - this.validateNotExceeding('containerCpu', props.cpu ?? 256, props.containerCpu); - this.validateNotExceeding('containerMemoryLimitMiB', props.memoryLimitMiB ?? 512, props.containerMemoryLimitMiB); + this.validateContainerCpu(props.containerCpu, props.cpu); + this.validateContainerMemoryLimitMiB(props.containerMemoryLimitMiB, props.memoryLimitMiB); const taskImageOptions = props.taskImageOptions; this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { @@ -179,12 +176,36 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } /** - * Throws an error if the specified value is greater than the limit. + * Throws an error if containerCpu is greater than cpu or is a not positive integer. + * @param containerCpu The minimum number of CPU units to reserve for the container. + * @param cpu The number of cpu units used by the task. (default: 256) */ - private validateNotExceeding(name: string, limit: number, value?: number) { - if (value === undefined || Token.isUnresolved(value)) { return; } - if (value > limit) { - throw new Error(`${name}: Must be less than or equal to ${limit}; received ${value}`); + private validateContainerCpu(containerCpu?: number, cpu: number = 256) { + if (containerCpu === undefined || Token.isUnresolved(containerCpu) || Token.isUnresolved(cpu)) { + return; + } + if (containerCpu > cpu) { + throw new Error('containerCpu must be less than to cpu'); + } + if (containerCpu < 0 || !Number.isInteger(containerCpu)) { + throw new Error('containerCpu must be positive integer'); + } + } + + /** + * Throws an error if containerMemoryLimitMiB is greater than memoryLimitMiB or is a not positive integer. + * @param containerMemoryLimitMiB The amount (in MiB) of memory to present to the container. + * @param memoryLimitMiB The amount (in MiB) of memory used by the task. (default: 512) + */ + private validateContainerMemoryLimitMiB(containerMemoryLimitMiB?: number, memoryLimitMiB: number = 512) { + if (containerMemoryLimitMiB === undefined || Token.isUnresolved(containerMemoryLimitMiB) || Token.isUnresolved(memoryLimitMiB)) { + return; + } + if (containerMemoryLimitMiB > memoryLimitMiB) { + throw new Error('containerMemoryLimitMiB must be less than to memoryLimitMiB'); + } + if (containerMemoryLimitMiB < 0 || !Number.isInteger(containerMemoryLimitMiB)) { + throw new Error('containerMemoryLimitMiB must be positive integer'); } } } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index 06eb6acc83909..cf1f2d02ad3ee 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1479,7 +1479,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 512, }); - }).toThrow('containerCpu: Must be less than or equal to 256; received 512'); + }).toThrow('containerCpu must be less than to cpu'); }); describe('errors when containerCpu is not positive integer', () => { @@ -1500,7 +1500,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: -1, }); - }).toThrow('containerCpu: Must be a non-negative integer; received -1'); + }).toThrow('containerCpu must be positive integer'); }); test('when containerCpu is float', () => { @@ -1520,7 +1520,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 0.5, }); - }).toThrow('containerCpu: Must be a non-negative integer; received 0.5'); + }).toThrow('containerCpu must be positive integer'); }); }); @@ -1541,7 +1541,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 512, }); - }).toThrow('containerMemoryLimitMiB: Must be less than or equal to 256; received 512'); + }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB'); }); describe('errors when containerMemoryLimitMiB is not positive integer', () => { @@ -1562,7 +1562,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: -1, }); - }).toThrow('containerMemoryLimitMiB: Must be a non-negative integer; received -1'); + }).toThrow('containerMemoryLimitMiB must be positive integer'); }); test('when containerMemoryLimitMiB is float', () => { @@ -1582,7 +1582,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 0.5, }); - }).toThrow('containerMemoryLimitMiB: Must be a non-negative integer; received 0.5'); + }).toThrow('containerMemoryLimitMiB must be positive integer'); }); }); }); From 1c5d8cf272b6a385dd7edd1e57bc51a768d0cedb Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 17:29:42 +0900 Subject: [PATCH 15/22] feat: move validation method --- .../fargate/application-load-balanced-fargate-service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 46128e4e6104d..876d5179b5b6f 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -87,9 +87,6 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } else if (props.taskDefinition) { this.taskDefinition = props.taskDefinition; } else if (props.taskImageOptions) { - this.validateContainerCpu(props.containerCpu, props.cpu); - this.validateContainerMemoryLimitMiB(props.containerMemoryLimitMiB, props.memoryLimitMiB); - const taskImageOptions = props.taskImageOptions; this.taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { memoryLimitMiB: props.memoryLimitMiB, @@ -107,6 +104,9 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc ? taskImageOptions.logDriver : enableLogging ? this.createAWSLogDriver(this.node.id) : undefined; + this.validateContainerCpu(props.containerCpu, props.cpu); + this.validateContainerMemoryLimitMiB(props.containerMemoryLimitMiB, props.memoryLimitMiB); + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, From 707a331261163204318ca833786c140fda4f77a1 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 17:31:21 +0900 Subject: [PATCH 16/22] feat: delete private method JsDoc --- .../application-load-balanced-fargate-service.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 876d5179b5b6f..505ef39ce9ab9 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -175,11 +175,6 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } } - /** - * Throws an error if containerCpu is greater than cpu or is a not positive integer. - * @param containerCpu The minimum number of CPU units to reserve for the container. - * @param cpu The number of cpu units used by the task. (default: 256) - */ private validateContainerCpu(containerCpu?: number, cpu: number = 256) { if (containerCpu === undefined || Token.isUnresolved(containerCpu) || Token.isUnresolved(cpu)) { return; @@ -192,11 +187,6 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } } - /** - * Throws an error if containerMemoryLimitMiB is greater than memoryLimitMiB or is a not positive integer. - * @param containerMemoryLimitMiB The amount (in MiB) of memory to present to the container. - * @param memoryLimitMiB The amount (in MiB) of memory used by the task. (default: 512) - */ private validateContainerMemoryLimitMiB(containerMemoryLimitMiB?: number, memoryLimitMiB: number = 512) { if (containerMemoryLimitMiB === undefined || Token.isUnresolved(containerMemoryLimitMiB) || Token.isUnresolved(memoryLimitMiB)) { return; From 2b7a189843299d8a4386c906cd8edf5f5c779775 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 18:03:25 +0900 Subject: [PATCH 17/22] feat: change error message --- .../application-load-balanced-fargate-service.ts | 8 ++++---- .../fargate/load-balanced-fargate-service.test.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 505ef39ce9ab9..f810218cda3c9 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -180,10 +180,10 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc return; } if (containerCpu > cpu) { - throw new Error('containerCpu must be less than to cpu'); + throw new Error(`containerCpu must be less than to cpu; received containerCpu: ${containerCpu}, cpu: ${cpu}`); } if (containerCpu < 0 || !Number.isInteger(containerCpu)) { - throw new Error('containerCpu must be positive integer'); + throw new Error(`containerCpu must be a non-negative integer; received ${containerCpu}`); } } @@ -192,10 +192,10 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc return; } if (containerMemoryLimitMiB > memoryLimitMiB) { - throw new Error('containerMemoryLimitMiB must be less than to memoryLimitMiB'); + throw new Error(`containerMemoryLimitMiB must be less than to memoryLimitMiB; received containerMemoryLimitMiB: ${containerMemoryLimitMiB}, memoryLimitMiB: ${memoryLimitMiB}`); } if (containerMemoryLimitMiB < 0 || !Number.isInteger(containerMemoryLimitMiB)) { - throw new Error('containerMemoryLimitMiB must be positive integer'); + throw new Error(`containerMemoryLimitMiB must be a non-negative integer; received ${containerMemoryLimitMiB}`); } } } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index cf1f2d02ad3ee..f5a61e2bed53d 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1479,7 +1479,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 512, }); - }).toThrow('containerCpu must be less than to cpu'); + }).toThrow('containerCpu must be less than to cpu; received containerCpu: 512, cpu: 256'); }); describe('errors when containerCpu is not positive integer', () => { @@ -1500,7 +1500,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: -1, }); - }).toThrow('containerCpu must be positive integer'); + }).toThrow('containerCpu must be a non-negative integer; received -1'); }); test('when containerCpu is float', () => { @@ -1520,7 +1520,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerCpu: 0.5, }); - }).toThrow('containerCpu must be positive integer'); + }).toThrow('containerCpu must be a non-negative integer; received 0.5'); }); }); @@ -1541,7 +1541,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 512, }); - }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB'); + }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB; received containerMemoryLimitMiB: 512, memoryLimitMiB: 256'); }); describe('errors when containerMemoryLimitMiB is not positive integer', () => { @@ -1562,7 +1562,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: -1, }); - }).toThrow('containerMemoryLimitMiB must be positive integer'); + }).toThrow('containerMemoryLimitMiB must be a non-negative integer; received -1'); }); test('when containerMemoryLimitMiB is float', () => { @@ -1582,7 +1582,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 0.5, }); - }).toThrow('containerMemoryLimitMiB must be positive integer'); + }).toThrow('containerMemoryLimitMiB must be a non-negative integer; received 0.5'); }); }); }); From 38c926382261cf5cd7a7e02710c4e6184945eec1 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 18:19:02 +0900 Subject: [PATCH 18/22] feat: update containerCpu validation --- .../lib/fargate/application-load-balanced-fargate-service.ts | 4 ++-- .../test/fargate/load-balanced-fargate-service.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index f810218cda3c9..0167712817584 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -194,8 +194,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc if (containerMemoryLimitMiB > memoryLimitMiB) { throw new Error(`containerMemoryLimitMiB must be less than to memoryLimitMiB; received containerMemoryLimitMiB: ${containerMemoryLimitMiB}, memoryLimitMiB: ${memoryLimitMiB}`); } - if (containerMemoryLimitMiB < 0 || !Number.isInteger(containerMemoryLimitMiB)) { - throw new Error(`containerMemoryLimitMiB must be a non-negative integer; received ${containerMemoryLimitMiB}`); + if (containerMemoryLimitMiB <= 0 || !Number.isInteger(containerMemoryLimitMiB)) { + throw new Error(`containerMemoryLimitMiB must be a positive integer; received ${containerMemoryLimitMiB}`); } } } diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index f5a61e2bed53d..fb4b9b44e120a 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1562,7 +1562,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: -1, }); - }).toThrow('containerMemoryLimitMiB must be a non-negative integer; received -1'); + }).toThrow('containerMemoryLimitMiB must be a positive integer; received -1'); }); test('when containerMemoryLimitMiB is float', () => { @@ -1582,7 +1582,7 @@ describe('ApplicationLoadBalancedFargateService', () => { loadBalancerName: 'alb-test-load-balancer', containerMemoryLimitMiB: 0.5, }); - }).toThrow('containerMemoryLimitMiB must be a non-negative integer; received 0.5'); + }).toThrow('containerMemoryLimitMiB must be a positive integer; received 0.5'); }); }); }); From f2243912fca179e576d1fb5d11274c9efcd17046 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 18:23:34 +0900 Subject: [PATCH 19/22] feat: add comment for validation method --- .../lib/fargate/application-load-balanced-fargate-service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 0167712817584..1f47e3678e279 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -175,7 +175,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } } - private validateContainerCpu(containerCpu?: number, cpu: number = 256) { + private validateContainerCpu(containerCpu?: number, cpu: number = 256) { // default value for cpu is 256 if (containerCpu === undefined || Token.isUnresolved(containerCpu) || Token.isUnresolved(cpu)) { return; } @@ -187,7 +187,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc } } - private validateContainerMemoryLimitMiB(containerMemoryLimitMiB?: number, memoryLimitMiB: number = 512) { + private validateContainerMemoryLimitMiB(containerMemoryLimitMiB?: number, memoryLimitMiB: number = 512) { // default value for memoryLimitMiB is 512 if (containerMemoryLimitMiB === undefined || Token.isUnresolved(containerMemoryLimitMiB) || Token.isUnresolved(memoryLimitMiB)) { return; } From d60a82c81569c47f43e975fb28a5de40c5a7d4f8 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 18:29:28 +0900 Subject: [PATCH 20/22] test: change test name --- .../load-balanced-fargate-service.test.ts | 156 +++++++++--------- 1 file changed, 76 insertions(+), 80 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index fb4b9b44e120a..0b04eb0d2c728 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1462,7 +1462,7 @@ describe('ApplicationLoadBalancedFargateService', () => { }); }); - test('errors when containerCpu is greater than cpu', () => { + test('throw when containerCpu is greater than cpu', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -1482,49 +1482,47 @@ describe('ApplicationLoadBalancedFargateService', () => { }).toThrow('containerCpu must be less than to cpu; received containerCpu: 512, cpu: 256'); }); - describe('errors when containerCpu is not positive integer', () => { - test('when containerCpu is negative integer', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.Vpc(stack, 'VPC'); - const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + test('throw when containerCpu is negative integer', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); - // THEN - expect(() => { - new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { - cluster, - taskImageOptions: { - image: ecs.ContainerImage.fromRegistry('test'), - }, - cpu: 256, - loadBalancerName: 'alb-test-load-balancer', - containerCpu: -1, - }); - }).toThrow('containerCpu must be a non-negative integer; received -1'); - }); - - test('when containerCpu is float', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.Vpc(stack, 'VPC'); - const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); - - // THEN - expect(() => { - new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { - cluster, - taskImageOptions: { - image: ecs.ContainerImage.fromRegistry('test'), - }, - cpu: 256, - loadBalancerName: 'alb-test-load-balancer', - containerCpu: 0.5, - }); - }).toThrow('containerCpu must be a non-negative integer; received 0.5'); - }); + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + cpu: 256, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: -1, + }); + }).toThrow('containerCpu must be a non-negative integer; received -1'); + }); + + test('throw when containerCpu is float', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + cpu: 256, + loadBalancerName: 'alb-test-load-balancer', + containerCpu: 0.5, + }); + }).toThrow('containerCpu must be a non-negative integer; received 0.5'); }); - test('errors when containerMemoryLimitMiB is greater than memoryLimitMiB', () => { + test('throw when containerMemoryLimitMiB is greater than memoryLimitMiB', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'VPC'); @@ -1544,46 +1542,44 @@ describe('ApplicationLoadBalancedFargateService', () => { }).toThrow('containerMemoryLimitMiB must be less than to memoryLimitMiB; received containerMemoryLimitMiB: 512, memoryLimitMiB: 256'); }); - describe('errors when containerMemoryLimitMiB is not positive integer', () => { - test('when containerMemoryLimitMiB is negative integer', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.Vpc(stack, 'VPC'); - const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + test('throw when containerMemoryLimitMiB is negative integer', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); - // THEN - expect(() => { - new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { - cluster, - taskImageOptions: { - image: ecs.ContainerImage.fromRegistry('test'), - }, - memoryLimitMiB: 256, - loadBalancerName: 'alb-test-load-balancer', - containerMemoryLimitMiB: -1, - }); - }).toThrow('containerMemoryLimitMiB must be a positive integer; received -1'); - }); - - test('when containerMemoryLimitMiB is float', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.Vpc(stack, 'VPC'); - const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); - - // THEN - expect(() => { - new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { - cluster, - taskImageOptions: { - image: ecs.ContainerImage.fromRegistry('test'), - }, - memoryLimitMiB: 256, - loadBalancerName: 'alb-test-load-balancer', - containerMemoryLimitMiB: 0.5, - }); - }).toThrow('containerMemoryLimitMiB must be a positive integer; received 0.5'); - }); + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + memoryLimitMiB: 256, + loadBalancerName: 'alb-test-load-balancer', + containerMemoryLimitMiB: -1, + }); + }).toThrow('containerMemoryLimitMiB must be a positive integer; received -1'); + }); + + test('throw when containerMemoryLimitMiB is float', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + memoryLimitMiB: 256, + loadBalancerName: 'alb-test-load-balancer', + containerMemoryLimitMiB: 0.5, + }); + }).toThrow('containerMemoryLimitMiB must be a positive integer; received 0.5'); }); }); From ad069fe6e0a3ed08aa4ae441384332aeae82e145 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Fri, 23 Aug 2024 18:52:26 +0900 Subject: [PATCH 21/22] test: add test case --- .../load-balanced-fargate-service.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts index 0b04eb0d2c728..7d55babf46df4 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/test/fargate/load-balanced-fargate-service.test.ts @@ -1581,6 +1581,26 @@ describe('ApplicationLoadBalancedFargateService', () => { }); }).toThrow('containerMemoryLimitMiB must be a positive integer; received 0.5'); }); + + test('throw when containerMemoryLimitMiB is 0', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + + // THEN + expect(() => { + new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', { + cluster, + taskImageOptions: { + image: ecs.ContainerImage.fromRegistry('test'), + }, + memoryLimitMiB: 256, + loadBalancerName: 'alb-test-load-balancer', + containerMemoryLimitMiB: 0, + }); + }).toThrow('containerMemoryLimitMiB must be a positive integer; received 0'); + }); }); describe('NetworkLoadBalancedFargateService', () => { From 89290c648a2234479802e1218b6dd2e47f7b1b33 Mon Sep 17 00:00:00 2001 From: ren-yamanashi Date: Wed, 28 Aug 2024 22:49:52 +0900 Subject: [PATCH 22/22] feat: add comment for validation method --- .../lib/fargate/application-load-balanced-fargate-service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 1f47e3678e279..314cdad0629da 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -182,6 +182,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc if (containerCpu > cpu) { throw new Error(`containerCpu must be less than to cpu; received containerCpu: ${containerCpu}, cpu: ${cpu}`); } + // If containerCPU is 0, it is not an error. if (containerCpu < 0 || !Number.isInteger(containerCpu)) { throw new Error(`containerCpu must be a non-negative integer; received ${containerCpu}`); }