From a9fdf7fe0d2f0fbf450feb52a145b635ddda9688 Mon Sep 17 00:00:00 2001 From: Piradeep Kandasamy Date: Thu, 2 May 2019 15:44:44 -0700 Subject: [PATCH] Fix memoryReservationLimit not being set in LoadBalancedEcsService --- .../aws-ecs/lib/load-balanced-ecs-service.ts | 7 +++-- packages/@aws-cdk/aws-ecs/test/test.l3s.ts | 31 ++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts index 31564226042cc..0d25fe4fa204f 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts @@ -42,17 +42,18 @@ export class LoadBalancedEc2Service extends LoadBalancedServiceBase { const container = taskDefinition.addContainer('web', { image: props.image, memoryLimitMiB: props.memoryLimitMiB, - environment: props.environment, + memoryReservationMiB: props.memoryReservationMiB, + environment: props.environment }); container.addPortMappings({ - containerPort: props.containerPort || 80, + containerPort: props.containerPort || 80 }); const service = new Ec2Service(this, "Service", { cluster: props.cluster, desiredCount: props.desiredCount || 1, - taskDefinition, + taskDefinition }); this.addServiceAsTarget(service); diff --git a/packages/@aws-cdk/aws-ecs/test/test.l3s.ts b/packages/@aws-cdk/aws-ecs/test/test.l3s.ts index cfc9318178ea2..e36a5a2005f9f 100644 --- a/packages/@aws-cdk/aws-ecs/test/test.l3s.ts +++ b/packages/@aws-cdk/aws-ecs/test/test.l3s.ts @@ -26,7 +26,7 @@ export = { } }); - // THEN - stack containers a load balancer and a service + // THEN - stack contains a load balancer and a service expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer')); expect(stack).to(haveResource("AWS::ECS::Service", { @@ -47,6 +47,35 @@ export = { Value: "test environment variable 2 value" } ], + Memory: 1024 + } + ] + })); + + test.done(); + }, + + 'test ECS loadbalanced construct with memoryReservationMiB'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.VpcNetwork(stack, 'VPC'); + const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); + cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') }); + + // WHEN + new ecs.LoadBalancedEc2Service(stack, 'Service', { + cluster, + memoryReservationMiB: 1024, + image: ecs.ContainerImage.fromRegistry('test') + }); + + // THEN - stack contains a load balancer and a service + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer')); + + expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + MemoryReservation: 1024 } ] }));