Skip to content

Commit

Permalink
feat(ecs-patterns): healthyPercent on ALB, NLB, Fargate (#4820)
Browse files Browse the repository at this point in the history
* feat(ecs-patterns): healthyPercent on ALB

* feat(ecs-patterns): healthyPercent NLB, ALB, Fargate

* feat(ecs-patterns): healthyPercent tests
  • Loading branch information
quincycs authored and mergify[bot] committed Dec 12, 2019
1 parent 748b5b3 commit 150e65c
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ export interface ApplicationLoadBalancedServiceBaseProps {
*/
readonly healthCheckGracePeriod?: cdk.Duration;

/**
* The maximum number of tasks, specified as a percentage of the Amazon ECS
* service's DesiredCount value, that can run in a service during a
* deployment.
*
* @default - 100 if daemon, otherwise 200
*/
readonly maxHealthyPercent?: number;

/**
* The minimum number of tasks, specified as a percentage of
* the Amazon ECS service's DesiredCount value, that must
* continue to run and remain healthy during a deployment.
*
* @default - 0 if daemon, otherwise 50
*/
readonly minHealthyPercent?: number;

/**
* The application load balancer that will serve traffic to the service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ export interface NetworkLoadBalancedServiceBaseProps {
*/
readonly healthCheckGracePeriod?: cdk.Duration;

/**
* The maximum number of tasks, specified as a percentage of the Amazon ECS
* service's DesiredCount value, that can run in a service during a
* deployment.
*
* @default - 100 if daemon, otherwise 200
*/
readonly maxHealthyPercent?: number;

/**
* The minimum number of tasks, specified as a percentage of
* the Amazon ECS service's DesiredCount value, that must
* continue to run and remain healthy during a deployment.
*
* @default - 0 if daemon, otherwise 50
*/
readonly minHealthyPercent?: number;

/**
* The network load balancer that will serve traffic to the service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
assignPublicIp: false,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
assignPublicIp: false,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
assignPublicIp: this.assignPublicIp,
serviceName: props.serviceName,
healthCheckGracePeriod: props.healthCheckGracePeriod,
minHealthyPercent: props.minHealthyPercent,
maxHealthyPercent: props.maxHealthyPercent,
propagateTags: props.propagateTags,
enableECSManagedTags: props.enableECSManagedTags,
cloudMapOptions: props.cloudMapOptions,
Expand Down
116 changes: 116 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,4 +782,120 @@ export = {

test.done();
},

'ALBFargate - having *HealthyPercent properties'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

// WHEN
new ecsPatterns.ApplicationLoadBalancedFargateService(stack, "ALB123Service", {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
minHealthyPercent: 100,
maxHealthyPercent: 200
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::Service', {
DeploymentConfiguration: {
MinimumHealthyPercent: 100,
MaximumPercent: 200
},
}));

test.done();
},

'NLBFargate - having *HealthyPercent properties'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

// WHEN
new ecsPatterns.NetworkLoadBalancedFargateService(stack, "Service", {
cluster,
memoryLimitMiB: 1024,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
desiredCount: 1,
minHealthyPercent: 100,
maxHealthyPercent: 200
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::Service', {
DeploymentConfiguration: {
MinimumHealthyPercent: 100,
MaximumPercent: 200,
},
}));

test.done();
},

'ALB - having *HealthyPercent properties'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });

// WHEN
new ecsPatterns.ApplicationLoadBalancedEc2Service(stack, "Service", {
cluster,
memoryLimitMiB: 1024,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
desiredCount: 1,
minHealthyPercent: 100,
maxHealthyPercent: 200
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::Service', {
DeploymentConfiguration: {
MinimumHealthyPercent: 100,
MaximumPercent: 200,
},
}));

test.done();
},

'NLB - having *HealthyPercent properties'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });

// WHEN
new ecsPatterns.NetworkLoadBalancedEc2Service(stack, "Service", {
cluster,
memoryLimitMiB: 1024,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
desiredCount: 1,
minHealthyPercent: 100,
maxHealthyPercent: 200
});

// THEN
expect(stack).to(haveResourceLike('AWS::ECS::Service', {
DeploymentConfiguration: {
MinimumHealthyPercent: 100,
MaximumPercent: 200,
},
}));

test.done();
},
};

0 comments on commit 150e65c

Please sign in to comment.