Skip to content

Commit

Permalink
fix(ecs): fix memoryReservationLimit in LoadBalancedEcsService (#2463)
Browse files Browse the repository at this point in the history
Previously, only `memoryLimitMiB` was being set in the constructor. This would cause an unexpected validation error when a LoadBalancedEcsService was instantiated with `memoryReservationMiB` only specified. This fix correctly sets both fields.

Fixes #2263
  • Loading branch information
piradeepk authored and rix0rrr committed May 6, 2019
1 parent 1df4e2d commit 6b50927
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 30 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/test.l3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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
}
]
}));
Expand Down

0 comments on commit 6b50927

Please sign in to comment.