Skip to content

Commit

Permalink
Fix memoryReservationLimit not being set in LoadBalancedEcsService
Browse files Browse the repository at this point in the history
  • Loading branch information
piradeepk committed May 3, 2019
1 parent fd74d07 commit a9fdf7f
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 a9fdf7f

Please sign in to comment.