Skip to content

Commit 6b50927

Browse files
piradeepkrix0rrr
authored andcommitted
fix(ecs): fix memoryReservationLimit in LoadBalancedEcsService (#2463)
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
1 parent 1df4e2d commit 6b50927

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ export class LoadBalancedEc2Service extends LoadBalancedServiceBase {
4242
const container = taskDefinition.addContainer('web', {
4343
image: props.image,
4444
memoryLimitMiB: props.memoryLimitMiB,
45-
environment: props.environment,
45+
memoryReservationMiB: props.memoryReservationMiB,
46+
environment: props.environment
4647
});
4748

4849
container.addPortMappings({
49-
containerPort: props.containerPort || 80,
50+
containerPort: props.containerPort || 80
5051
});
5152

5253
const service = new Ec2Service(this, "Service", {
5354
cluster: props.cluster,
5455
desiredCount: props.desiredCount || 1,
55-
taskDefinition,
56+
taskDefinition
5657
});
5758

5859
this.addServiceAsTarget(service);

packages/@aws-cdk/aws-ecs/test/test.l3s.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export = {
2626
}
2727
});
2828

29-
// THEN - stack containers a load balancer and a service
29+
// THEN - stack contains a load balancer and a service
3030
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));
3131

3232
expect(stack).to(haveResource("AWS::ECS::Service", {
@@ -47,6 +47,35 @@ export = {
4747
Value: "test environment variable 2 value"
4848
}
4949
],
50+
Memory: 1024
51+
}
52+
]
53+
}));
54+
55+
test.done();
56+
},
57+
58+
'test ECS loadbalanced construct with memoryReservationMiB'(test: Test) {
59+
// GIVEN
60+
const stack = new cdk.Stack();
61+
const vpc = new ec2.VpcNetwork(stack, 'VPC');
62+
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
63+
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });
64+
65+
// WHEN
66+
new ecs.LoadBalancedEc2Service(stack, 'Service', {
67+
cluster,
68+
memoryReservationMiB: 1024,
69+
image: ecs.ContainerImage.fromRegistry('test')
70+
});
71+
72+
// THEN - stack contains a load balancer and a service
73+
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));
74+
75+
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
76+
ContainerDefinitions: [
77+
{
78+
MemoryReservation: 1024
5079
}
5180
]
5281
}));

0 commit comments

Comments
 (0)