Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-ecs): set memoryReservationMiB in LoadBalancedEcsService #2463

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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