From 5f41f6199448afcb47556de4d6207273cb36f2c6 Mon Sep 17 00:00:00 2001 From: plastic-karma Date: Mon, 1 Jun 2020 15:43:37 -0700 Subject: [PATCH] feat(aws-ecs-patterns): adding min and max halth percentage to queue-processing fargate service fixes: https://github.com/aws/aws-cdk/issues/8277 --- .../lib/base/queue-processing-service-base.ts | 18 ++++++++++++++++++ .../lib/ecs/queue-processing-ecs-service.ts | 2 ++ .../queue-processing-fargate-service.ts | 2 ++ .../ec2/test.queue-processing-ecs-service.ts | 6 ++++++ .../test.queue-processing-fargate-service.ts | 6 ++++++ 5 files changed, 34 insertions(+) diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts index 6c43d4fd4aa6d..cd9e2f85f4633 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts @@ -147,6 +147,24 @@ export interface QueueProcessingServiceBaseProps { * @default - Automatically generated name. */ readonly family?: string; + + /** + * 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 - default from underlying service. + */ + 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 - default from underlying service. + */ + readonly minHealthyPercent?: number; } /** diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts index 0fb21d1f8263d..ff7cb0e905d98 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts @@ -96,6 +96,8 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase { desiredCount: this.desiredCount, taskDefinition: this.taskDefinition, serviceName: props.serviceName, + minHealthyPercent: props.minHealthyPercent, + maxHealthyPercent: props.maxHealthyPercent, propagateTags: props.propagateTags, enableECSManagedTags: props.enableECSManagedTags, }); diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts index a7da98ed1fbfc..b0f92abab6f23 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts @@ -101,6 +101,8 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase { desiredCount: this.desiredCount, taskDefinition: this.taskDefinition, serviceName: props.serviceName, + minHealthyPercent: props.minHealthyPercent, + maxHealthyPercent: props.maxHealthyPercent, propagateTags: props.propagateTags, enableECSManagedTags: props.enableECSManagedTags, platformVersion: props.platformVersion, diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.queue-processing-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.queue-processing-ecs-service.ts index 3bd580cb93176..4bfa0732591cb 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.queue-processing-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.queue-processing-ecs-service.ts @@ -179,6 +179,8 @@ export = { }, queue, maxScalingCapacity: 5, + minHealthyPercent: 60, + maxHealthyPercent: 150, serviceName: 'ecs-test-service', family: 'ecs-task-family', }); @@ -186,6 +188,10 @@ export = { // THEN - QueueWorker is of EC2 launch type, an SQS queue is created and all optional properties are set. expect(stack).to(haveResource('AWS::ECS::Service', { DesiredCount: 2, + DeploymentConfiguration: { + MinimumHealthyPercent: 60, + MaximumPercent: 150, + }, LaunchType: 'EC2', ServiceName: 'ecs-test-service', })); diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.queue-processing-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.queue-processing-fargate-service.ts index c37c7f349b496..4f0f434ef1f72 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.queue-processing-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.queue-processing-fargate-service.ts @@ -223,6 +223,8 @@ export = { }, queue, maxScalingCapacity: 5, + minHealthyPercent: 60, + maxHealthyPercent: 150, serviceName: 'fargate-test-service', family: 'fargate-task-family', platformVersion: ecs.FargatePlatformVersion.VERSION1_4, @@ -231,6 +233,10 @@ export = { // THEN - QueueWorker is of FARGATE launch type, an SQS queue is created and all optional properties are set. expect(stack).to(haveResource('AWS::ECS::Service', { DesiredCount: 2, + DeploymentConfiguration: { + MinimumHealthyPercent: 60, + MaximumPercent: 150, + }, LaunchType: 'FARGATE', ServiceName: 'fargate-test-service', PlatformVersion: ecs.FargatePlatformVersion.VERSION1_4,