From 925d76d60b7641dd188222b5c3bb2fd8ca8fe6c5 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 15:13:15 +1100 Subject: [PATCH 01/11] add warning if BaseService created with minHealthyPercent undefined --- aws-cdk.code-workspace | 11 +++++++++-- packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/aws-cdk.code-workspace b/aws-cdk.code-workspace index db36117c4c910..6e5f6cd74211a 100644 --- a/aws-cdk.code-workspace +++ b/aws-cdk.code-workspace @@ -1,5 +1,4 @@ { - "folders": [{ "path": "." }], "settings": { "jest.jestCommandLine": "node_modules/.bin/jest", "jest.autoRun": "off", @@ -34,5 +33,13 @@ }, "extensions": { "recommendations": ["dbaeumer.vscode-eslint", "Orta.vscode-jest"] - } + }, + "folders": [ + { + "path": "." + }, + { + "path": "../cdkApp" + } + ] } diff --git a/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts b/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts index 9f5891ba78e55..9c627fe7d0baf 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts @@ -708,6 +708,10 @@ export abstract class BaseService extends Resource throw new Error('CODE_DEPLOY deploymentController can only be used with the `latest` task definition revision'); } + if (props.minHealthyPercent === undefined) { + Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs:minHealthyPercent', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705'); + } + if (props.deploymentController?.type === DeploymentControllerType.CODE_DEPLOY) { // Strip the revision ID from the service's task definition property to // prevent new task def revisions in the stack from triggering updates From 349944d139b767a601f6faef4abfa3415db73612 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 15:57:00 +1100 Subject: [PATCH 02/11] add tests to FargateService and Ec2Service --- .../aws-ecs/test/ec2/ec2-service.test.ts | 45 +++++++++++++++++++ .../test/fargate/fargate-service.test.ts | 42 +++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts index b6aff9a744f7a..47f36732ecdb1 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts @@ -1630,6 +1630,51 @@ describe('ec2 service', () => { }); + test('warning if minHealthyPercent not set', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); + + const container = taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + new ecs.Ec2Service(stack, 'Ec2Service', { + cluster, + taskDefinition, + }); + + // THEN + Annotations.fromStack(stack).hasWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + + test('no warning if minHealthyPercent set', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); + + const container = taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + new ecs.Ec2Service(stack, 'Ec2Service', { + cluster, + taskDefinition, + minHealthyPercent: 50, + }); + + // THEN + Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + describe('with a TaskDefinition with Bridge network mode', () => { test('it errors if vpcSubnets is specified', () => { // GIVEN diff --git a/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts index 9abe512daefa5..578886df451cd 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts @@ -1343,6 +1343,47 @@ describe('fargate service', () => { }, }); }); + + test('warning if minHealthyPercent not set', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); + + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }); + + const service = new ecs.FargateService(stack, 'FargateService', { + cluster, + taskDefinition, + }); + + // THEN + Annotations.fromStack(stack).hasWarning('/Default/FargateService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + + test('no warning if minHealthyPercent set', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef'); + + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + }); + + const service = new ecs.FargateService(stack, 'FargateService', { + cluster, + taskDefinition, + minHealthyPercent: 50, + }); + + // THEN + Annotations.fromStack(stack).hasNoWarning('/Default/FargateService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) }); describe('when enabling service connect', () => { @@ -3502,6 +3543,7 @@ describe('fargate service', () => { const service = new ecs.FargateService(stack, 'Service', { cluster, taskDefinition, + minHealthyPercent: 50, // must be set to avoid warning causing test failure }); // WHEN From ed398fe0d138dafa8e7dfed7f24329e4c2186ea4 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 16:16:01 +1100 Subject: [PATCH 03/11] add warning and test for Ec2Service for daemon services specifically --- .../aws-ecs/lib/ec2/ec2-service.ts | 6 ++- .../aws-ecs/test/ec2/ec2-service.test.ts | 49 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ecs/lib/ec2/ec2-service.ts b/packages/aws-cdk-lib/aws-ecs/lib/ec2/ec2-service.ts index 09c731f40517f..0b5eeae081948 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/ec2/ec2-service.ts @@ -1,6 +1,6 @@ import { Construct } from 'constructs'; import * as ec2 from '../../../aws-ec2'; -import { Lazy, Resource, Stack } from '../../../core'; +import { Lazy, Resource, Stack, Annotations } from '../../../core'; import { BaseService, BaseServiceOptions, DeploymentControllerType, IBaseService, IService, LaunchType } from '../base/base-service'; import { fromServiceAttributes, extractServiceNameFromArn } from '../base/from-service-attributes'; import { NetworkMode, TaskDefinition } from '../base/task-definition'; @@ -220,6 +220,10 @@ export class Ec2Service extends BaseService implements IEc2Service { }); this.node.addValidation({ validate: this.validateEc2Service.bind(this) }); + + if (props.minHealthyPercent === undefined && props.daemon) { + Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs:minHealthyPercentDaemon', 'minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705'); + } } /** diff --git a/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts index 47f36732ecdb1..28b9d8208b6a1 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts @@ -1675,6 +1675,55 @@ describe('ec2 service', () => { Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); }) + test('warning if minHealthyPercent not set for a daemon service', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); + + const container = taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + new ecs.Ec2Service(stack, 'Ec2Service', { + cluster, + taskDefinition, + daemon: true + }); + + // THEN + Annotations.fromStack(stack).hasWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentDaemon]'); + Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + + test('no warning if minHealthyPercent set for a daemon service', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); + + const container = taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + new ecs.Ec2Service(stack, 'Ec2Service', { + cluster, + taskDefinition, + minHealthyPercent: 50, + daemon: true, + }); + + // THEN + Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentDaemon]'); + Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + describe('with a TaskDefinition with Bridge network mode', () => { test('it errors if vpcSubnets is specified', () => { // GIVEN From 41e295f35daf06432ba0ac4b9eb80fa666146a9a Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 16:45:30 +1100 Subject: [PATCH 04/11] rever aws-cdk.code-workspace --- aws-cdk.code-workspace | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/aws-cdk.code-workspace b/aws-cdk.code-workspace index 6e5f6cd74211a..54d5617cda1ad 100644 --- a/aws-cdk.code-workspace +++ b/aws-cdk.code-workspace @@ -33,13 +33,5 @@ }, "extensions": { "recommendations": ["dbaeumer.vscode-eslint", "Orta.vscode-jest"] - }, - "folders": [ - { - "path": "." - }, - { - "path": "../cdkApp" - } - ] + } } From 85d0c76fa6047b952a67e75ef94eaaef6445ffd6 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 16:46:57 +1100 Subject: [PATCH 05/11] revert aws-cdk.code-workspace --- aws-cdk.code-workspace | 1 + 1 file changed, 1 insertion(+) diff --git a/aws-cdk.code-workspace b/aws-cdk.code-workspace index 54d5617cda1ad..db36117c4c910 100644 --- a/aws-cdk.code-workspace +++ b/aws-cdk.code-workspace @@ -1,4 +1,5 @@ { + "folders": [{ "path": "." }], "settings": { "jest.jestCommandLine": "node_modules/.bin/jest", "jest.autoRun": "off", From 15e6a0cae01c305781ac4140dcd95f100efbcfdd Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 17:27:38 +1100 Subject: [PATCH 06/11] update aws-ecs/README.md examples to not generate warnings --- packages/aws-cdk-lib/aws-ecs/README.md | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs/README.md b/packages/aws-cdk-lib/aws-ecs/README.md index dce4c0c88c817..76a0e49414600 100644 --- a/packages/aws-cdk-lib/aws-ecs/README.md +++ b/packages/aws-cdk-lib/aws-ecs/README.md @@ -35,6 +35,7 @@ taskDefinition.addContainer('DefaultContainer', { const ecsService = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, }); ``` @@ -761,6 +762,7 @@ const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, desiredCount: 5, + minHealthyPercent: 100, }); ``` @@ -774,6 +776,7 @@ const service = new ecs.ExternalService(this, 'Service', { cluster, taskDefinition, desiredCount: 5, + minHealthyPercent: 100, }); ``` @@ -794,14 +797,16 @@ new ecs.ExternalService(this, 'Service', { cluster, taskDefinition, desiredCount: 5, - taskDefinitionRevision: ecs.TaskDefinitionRevision.of(1) + minHealthyPercent: 100, + taskDefinitionRevision: ecs.TaskDefinitionRevision.of(1), }); new ecs.ExternalService(this, 'Service', { cluster, taskDefinition, desiredCount: 5, - taskDefinitionRevision: ecs.TaskDefinitionRevision.LATEST + minHealthyPercent: 100, + taskDefinitionRevision: ecs.TaskDefinitionRevision.LATEST, }); ``` @@ -822,6 +827,7 @@ declare const taskDefinition: ecs.TaskDefinition; const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, circuitBreaker: { enable: true, rollback: true @@ -858,6 +864,7 @@ declare const elbAlarm: cw.Alarm; const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, deploymentAlarms: { alarmNames: [elbAlarm.alarmName], behavior: ecs.AlarmBehavior.ROLLBACK_ON_ALARM, @@ -944,6 +951,7 @@ const service = new ecs.FargateService(this, 'Service', { serviceName, cluster, taskDefinition, + minHealthyPercent: 100, }); const cpuMetric = new cw.Metric({ @@ -981,7 +989,7 @@ on the service, there will be no restrictions on the alarm name. declare const vpc: ec2.Vpc; declare const cluster: ecs.Cluster; declare const taskDefinition: ecs.TaskDefinition; -const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition }); +const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, minHealthyPercent: 100 }); const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', { vpc, internetFacing: true }); const listener = lb.addListener('Listener', { port: 80 }); @@ -1008,7 +1016,7 @@ Alternatively, you can also create all load balancer targets to be registered in declare const cluster: ecs.Cluster; declare const taskDefinition: ecs.TaskDefinition; declare const vpc: ec2.Vpc; -const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition }); +const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, minHealthyPercent: 100 }); const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', { vpc, internetFacing: true }); const listener = lb.addListener('Listener', { port: 80 }); @@ -1047,7 +1055,7 @@ for the alternatives. declare const cluster: ecs.Cluster; declare const taskDefinition: ecs.TaskDefinition; declare const vpc: ec2.Vpc; -const service = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition }); +const service = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition, minHealthyPercent: 100 }); const lb = new elb.LoadBalancer(this, 'LB', { vpc }); lb.addListener({ externalPort: 80 }); @@ -1060,7 +1068,7 @@ Similarly, if you want to have more control over load balancer targeting: declare const cluster: ecs.Cluster; declare const taskDefinition: ecs.TaskDefinition; declare const vpc: ec2.Vpc; -const service = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition }); +const service = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition, minHealthyPercent: 100 }); const lb = new elb.LoadBalancer(this, 'LB', { vpc }); lb.addListener({ externalPort: 80 }); @@ -1396,6 +1404,7 @@ specificContainer.addPortMappings({ new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, cloudMapOptions: { // Create SRV records - useful for bridge networking dnsRecordType: cloudmap.DnsRecordType.SRV, @@ -1453,6 +1462,7 @@ taskDefinition.addContainer('web', { new ecs.FargateService(this, 'FargateService', { cluster, taskDefinition, + minHealthyPercent: 100, capacityProviderStrategies: [ { capacityProvider: 'FARGATE_SPOT', @@ -1530,6 +1540,7 @@ taskDefinition.addContainer('web', { new ecs.Ec2Service(this, 'EC2Service', { cluster, taskDefinition, + minHealthyPercent: 100, capacityProviderStrategies: [ { capacityProvider: capacityProvider.capacityProviderName, @@ -1626,6 +1637,7 @@ declare const taskDefinition: ecs.TaskDefinition; const service = new ecs.Ec2Service(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, enableExecuteCommand: true, }); ``` @@ -1699,6 +1711,7 @@ cluster.addDefaultCloudMapNamespace({ const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, serviceConnectConfiguration: { services: [ { @@ -1723,6 +1736,7 @@ declare const taskDefinition: ecs.TaskDefinition; const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, }); service.enableServiceConnect(); ``` @@ -1736,6 +1750,7 @@ declare const taskDefinition: ecs.TaskDefinition; const customService = new ecs.FargateService(this, 'CustomizedService', { cluster, taskDefinition, + minHealthyPercent: 100, serviceConnectConfiguration: { logDriver: ecs.LogDrivers.awsLogs({ streamPrefix: 'sc-traffic', @@ -1765,6 +1780,7 @@ declare const taskDefinition: ecs.TaskDefinition; const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, + minHealthyPercent: 100, serviceConnectConfiguration: { services: [ { @@ -1828,6 +1844,7 @@ taskDefinition.addVolume(volume); const service = new ecs.FargateService(this, 'FargateService', { cluster, taskDefinition, + minHealthyPercent: 100, }); service.addVolume(volume); @@ -1857,6 +1874,7 @@ taskDefinition.addVolume(volumeFromSnapshot); const service = new ecs.FargateService(this, 'FargateService', { cluster, taskDefinition, + minHealthyPercent: 100, }); service.addVolume(volumeFromSnapshot); From a10c2b646537c5f24570e76767ea52455dd9cead Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 17:36:47 +1100 Subject: [PATCH 07/11] update aws-ecs-patterns/README.md examples to not generate warnings --- .../aws-cdk-lib/aws-ecs-patterns/README.md | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/README.md b/packages/aws-cdk-lib/aws-ecs-patterns/README.md index 1d3edbcc00a12..82781d8beb8bf 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/README.md +++ b/packages/aws-cdk-lib/aws-ecs-patterns/README.md @@ -30,6 +30,7 @@ const loadBalancedEcsService = new ecsPatterns.ApplicationLoadBalancedEc2Service entryPoint: ['entry', 'point'], }, desiredCount: 2, + minHealthyPercent: 100, }); ``` @@ -46,6 +47,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat command: ['command'], entryPoint: ['entry', 'point'], }, + minHealthyPercent: 100, }); loadBalancedFargateService.targetGroup.configureHealthCheck({ @@ -85,6 +87,7 @@ const loadBalancedEc2Service = new ecsPatterns.ApplicationMultipleTargetGroupsEc taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, targetGroups: [ { containerPort: 80, @@ -110,6 +113,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, targetGroups: [ { containerPort: 80, @@ -142,6 +146,7 @@ const loadBalancedEcsService = new ecsPatterns.NetworkLoadBalancedEc2Service(thi }, }, desiredCount: 2, + minHealthyPercent: 100, }); ``` @@ -156,6 +161,7 @@ const loadBalancedFargateService = new ecsPatterns.NetworkLoadBalancedFargateSer taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, }); ``` @@ -178,6 +184,7 @@ const loadBalancedEc2Service = new ecsPatterns.NetworkMultipleTargetGroupsEc2Ser taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, loadBalancers: [ { name: 'lb1', @@ -220,6 +227,7 @@ const loadBalancedFargateService = new ecsPatterns.NetworkMultipleTargetGroupsFa taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, loadBalancers: [ { name: 'lb1', @@ -272,6 +280,7 @@ const queueProcessingEc2Service = new ecsPatterns.QueueProcessingEc2Service(this }, maxScalingCapacity: 5, containerName: 'test', + minHealthyPercent: 100, }); ``` @@ -292,6 +301,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ }, maxScalingCapacity: 5, containerName: 'test', + minHealthyPercent: 100, }); ``` @@ -314,6 +324,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ }, maxScalingCapacity: 5, containerName: 'test', + minHealthyPercent: 100, disableCpuBasedScaling: true, }); ``` @@ -332,6 +343,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ environment: {}, maxScalingCapacity: 5, containerName: 'test', + minHealthyPercent: 100, cpuTargetUtilizationPercent: 90, }); ``` @@ -392,6 +404,7 @@ declare const cluster: ecs.Cluster; const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', { vpc, cluster, + minHealthyPercent: 100, certificate, sslPolicy: SslPolicy.RECOMMENDED, domainName: 'api.example.com', @@ -414,6 +427,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, capacityProviderStrategies: [ { capacityProvider: 'FARGATE_SPOT', @@ -441,6 +455,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, }); const scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount({ @@ -471,6 +486,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, }); const scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount({ @@ -499,6 +515,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, deploymentController: { type: ecs.DeploymentControllerType.CODE_DEPLOY, }, @@ -522,6 +539,7 @@ const service = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Ser taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, circuitBreaker: { rollback: true }, }); ``` @@ -553,6 +571,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ vpc, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, securityGroups: [securityGroup], taskSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED }, }); @@ -566,6 +585,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ vpc, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, assignPublicIp: true, }); ``` @@ -578,6 +598,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ vpc, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, maxReceiveCount: 42, retentionPeriod: Duration.days(7), visibilityTimeout: Duration.minutes(5), @@ -595,6 +616,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ vpc, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, assignPublicIp: true, cooldown: Duration.seconds(500), }); @@ -610,6 +632,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ cluster, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, capacityProviderStrategies: [ { capacityProvider: 'FARGATE_SPOT', @@ -632,6 +655,7 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ vpc, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, healthCheck: { command: [ "CMD-SHELL", "curl -f http://localhost/ || exit 1" ], // the properties below are optional @@ -664,6 +688,7 @@ const queueProcessingEc2Service = new ecsPatterns.QueueProcessingEc2Service(this cluster, memoryLimitMiB: 512, image: ecs.ContainerImage.fromRegistry('test'), + minHealthyPercent: 100, capacityProviderStrategies: [ { capacityProvider: capacityProvider.capacityProviderName, @@ -684,6 +709,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, taskSubnets: { subnets: [ec2.Subnet.fromSubnetId(this, 'subnet', 'VpcISOLATEDSubnet1Subnet80F07FA0')], }, @@ -702,6 +728,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, idleTimeout: Duration.seconds(120), }); ``` @@ -721,6 +748,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, enableExecuteCommand: true, loadBalancers: [ { @@ -793,6 +821,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, enableExecuteCommand: true, loadBalancers: [ { @@ -881,6 +910,7 @@ const applicationLoadBalancedFargateService = new ecsPatterns.ApplicationLoadBal taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, runtimePlatform: { cpuArchitecture: ecs.CpuArchitecture.ARM64, operatingSystemFamily: ecs.OperatingSystemFamily.LINUX, @@ -946,6 +976,7 @@ const securityGroup = new ec2.SecurityGroup(this, 'SG', { vpc }); const scheduledFargateTask = new ecsPatterns.ScheduledFargateTask(this, 'ScheduledFargateTask', { cluster, + minHealthyPercent: 100, scheduledFargateTaskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), memoryLimitMiB: 512, @@ -966,6 +997,7 @@ const service = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Ser cluster, vpc, desiredCount: 1, + minHealthyPercent: 100, taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), dockerLabels: { @@ -992,6 +1024,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, taskSubnets: { subnets: [ec2.Subnet.fromSubnetId(this, 'subnet', 'VpcISOLATEDSubnet1Subnet80F07FA0')], }, @@ -1020,6 +1053,7 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargat taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, + minHealthyPercent: 100, enableExecuteCommand: true }); ``` @@ -1095,6 +1129,7 @@ const applicationLoadBalancedFargateService = new ecsPatterns.ApplicationLoadBal taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, }); const networkLoadBalancedFargateService = new ecsPatterns.NetworkLoadBalancedFargateService(this, 'NLBFargateServiceWithCustomEphemeralStorage', { @@ -1105,6 +1140,7 @@ const networkLoadBalancedFargateService = new ecsPatterns.NetworkLoadBalancedFar taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, }); ``` @@ -1119,6 +1155,7 @@ const queueProcessingFargateService = new ecsPatterns.NetworkLoadBalancedFargate taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, securityGroups: [securityGroup], }); ``` @@ -1147,6 +1184,7 @@ const service = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'myS taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, ipAddressType: elbv2.IpAddressType.DUAL_STACK, }); @@ -1155,6 +1193,7 @@ const applicationLoadBalancedEc2Service = new ecsPatterns.ApplicationLoadBalance taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, ipAddressType: elbv2.IpAddressType.DUAL_STACK, }); ``` @@ -1177,6 +1216,7 @@ const networkLoadbalancedFargateService = new ecsPatterns.NetworkLoadBalancedFar taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, ipAddressType: elbv2.IpAddressType.DUAL_STACK, }); @@ -1185,6 +1225,7 @@ const networkLoadbalancedEc2Service = new ecsPatterns.NetworkLoadBalancedEc2Serv taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, + minHealthyPercent: 100, ipAddressType: elbv2.IpAddressType.DUAL_STACK, }); ``` From 3b3d3547852be85e5e3684d1282ffce053518426 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 18:01:03 +1100 Subject: [PATCH 08/11] implement warning and tests for external services --- .../aws-ecs/lib/external/external-service.ts | 7 ++- .../test/external/external-service.test.ts | 51 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs/lib/external/external-service.ts b/packages/aws-cdk-lib/aws-ecs/lib/external/external-service.ts index 89b52f908554a..4c79f5b917e03 100644 --- a/packages/aws-cdk-lib/aws-ecs/lib/external/external-service.ts +++ b/packages/aws-cdk-lib/aws-ecs/lib/external/external-service.ts @@ -3,7 +3,7 @@ import * as appscaling from '../../../aws-applicationautoscaling'; import * as ec2 from '../../../aws-ec2'; import * as elbv2 from '../../../aws-elasticloadbalancingv2'; import * as cloudmap from '../../../aws-servicediscovery'; -import { ArnFormat, Resource, Stack } from '../../../core'; +import { ArnFormat, Resource, Stack, Annotations } from '../../../core'; import { AssociateCloudMapServiceOptions, BaseService, BaseServiceOptions, CloudMapOptions, DeploymentControllerType, EcsTarget, IBaseService, IEcsLoadBalancerTarget, IService, LaunchType, PropagatedTagSource } from '../base/base-service'; import { fromServiceAttributes } from '../base/from-service-attributes'; import { ScalableTaskCount } from '../base/scalable-task-count'; @@ -132,6 +132,11 @@ export class ExternalService extends BaseService implements IExternalService { this.node.addValidation({ validate: () => this.networkConfiguration !== undefined ? ['Network configurations not supported for an external service'] : [], }); + + if (props.minHealthyPercent === undefined) { + Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs:minHealthyPercentExternal', 'minHealthyPercent has not been configured so the default value of 0% for an external service is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705'); + } + } /** diff --git a/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts index d77246d693959..2c21bf1210bce 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts @@ -1,4 +1,4 @@ -import { Template } from '../../../assertions'; +import { Template, Annotations } from '../../../assertions'; import * as autoscaling from '../../../aws-autoscaling'; import * as cloudwatch from '../../../aws-cloudwatch'; import * as ec2 from '../../../aws-ec2'; @@ -581,6 +581,7 @@ describe('external service', () => { type: DeploymentControllerType.EXTERNAL, }, circuitBreaker: { rollback: true }, + minHealthyPercent: 100 // required to prevent test failure due to warning }); app.synth(); @@ -590,4 +591,52 @@ describe('external service', () => { 'Deployment circuit breaker requires the ECS deployment controller.', ]); }); + + test('warning if minHealthyPercent not set for an external service', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); + + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + const service = new ecs.ExternalService(stack, 'ExternalService', { + cluster, + taskDefinition, + }); + + // THEN + Annotations.fromStack(stack).hasWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 0% for an external service is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentExternal]'); + Annotations.fromStack(stack).hasNoWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + + test('no warning if minHealthyPercent set for an external service', () => { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.ExternalTaskDefinition(stack, 'ExternalTaskDef'); + + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + const service = new ecs.ExternalService(stack, 'ExternalService', { + cluster, + taskDefinition, + minHealthyPercent: 100 + }); + + // THEN + Annotations.fromStack(stack).hasNoWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 0% for an external service is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentExternal]'); + Annotations.fromStack(stack).hasNoWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); + }) + }); From afddde378a0f61a2ca9c66e10fff5df641d39b56 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 18:32:12 +1100 Subject: [PATCH 09/11] fix linting issue --- .../aws-ecs/test/ec2/ec2-service.test.ts | 46 +++++++++---------- .../test/external/external-service.test.ts | 8 ++-- .../test/fargate/fargate-service.test.ts | 4 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts index 28b9d8208b6a1..b40634812a452 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts @@ -1630,7 +1630,7 @@ describe('ec2 service', () => { }); - test('warning if minHealthyPercent not set', () => { + test('warning if minHealthyPercent not set', () => { // GIVEN const stack = new cdk.Stack(); const vpc = new ec2.Vpc(stack, 'MyVpc', {}); @@ -1650,30 +1650,30 @@ describe('ec2 service', () => { // THEN Annotations.fromStack(stack).hasWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); test('no warning if minHealthyPercent set', () => { - // GIVEN - const stack = new cdk.Stack(); - const vpc = new ec2.Vpc(stack, 'MyVpc', {}); - const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); - addDefaultCapacityProvider(cluster, stack, vpc); - const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); - - const container = taskDefinition.addContainer('web', { - image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), - memoryLimitMiB: 512, - }); - - new ecs.Ec2Service(stack, 'Ec2Service', { - cluster, - taskDefinition, - minHealthyPercent: 50, - }); + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); + addDefaultCapacityProvider(cluster, stack, vpc); + const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef'); + + const container = taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + new ecs.Ec2Service(stack, 'Ec2Service', { + cluster, + taskDefinition, + minHealthyPercent: 50, + }); // THEN Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); test('warning if minHealthyPercent not set for a daemon service', () => { // GIVEN @@ -1691,13 +1691,13 @@ describe('ec2 service', () => { new ecs.Ec2Service(stack, 'Ec2Service', { cluster, taskDefinition, - daemon: true + daemon: true, }); // THEN Annotations.fromStack(stack).hasWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentDaemon]'); Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); test('no warning if minHealthyPercent set for a daemon service', () => { // GIVEN @@ -1722,7 +1722,7 @@ describe('ec2 service', () => { // THEN Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 0% for a daemon service is used. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentDaemon]'); Annotations.fromStack(stack).hasNoWarning('/Default/Ec2Service', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); describe('with a TaskDefinition with Bridge network mode', () => { test('it errors if vpcSubnets is specified', () => { diff --git a/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts index 2c21bf1210bce..9eeb40aafee2e 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/external/external-service.test.ts @@ -581,7 +581,7 @@ describe('external service', () => { type: DeploymentControllerType.EXTERNAL, }, circuitBreaker: { rollback: true }, - minHealthyPercent: 100 // required to prevent test failure due to warning + minHealthyPercent: 100, // required to prevent test failure due to warning }); app.synth(); @@ -613,7 +613,7 @@ describe('external service', () => { // THEN Annotations.fromStack(stack).hasWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 0% for an external service is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentExternal]'); Annotations.fromStack(stack).hasNoWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); test('no warning if minHealthyPercent set for an external service', () => { // GIVEN @@ -631,12 +631,12 @@ describe('external service', () => { const service = new ecs.ExternalService(stack, 'ExternalService', { cluster, taskDefinition, - minHealthyPercent: 100 + minHealthyPercent: 100, }); // THEN Annotations.fromStack(stack).hasNoWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 0% for an external service is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercentExternal]'); Annotations.fromStack(stack).hasNoWarning('/Default/ExternalService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); }); diff --git a/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts b/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts index 578886df451cd..cb16b49500f86 100644 --- a/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts +++ b/packages/aws-cdk-lib/aws-ecs/test/fargate/fargate-service.test.ts @@ -1362,7 +1362,7 @@ describe('fargate service', () => { // THEN Annotations.fromStack(stack).hasWarning('/Default/FargateService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); test('no warning if minHealthyPercent set', () => { // GIVEN @@ -1383,7 +1383,7 @@ describe('fargate service', () => { // THEN Annotations.fromStack(stack).hasNoWarning('/Default/FargateService', 'minHealthyPercent has not been configured so the default value of 50% is used. The number of running tasks will decrease below the desired count during deployments etc. See https://github.com/aws/aws-cdk/issues/31705 [ack: @aws-cdk/aws-ecs:minHealthyPercent]'); - }) + }); }); describe('when enabling service connect', () => { From 6c9063a62b6326d283ee7f6cda5033060b7508fb Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 23:11:00 +1100 Subject: [PATCH 10/11] fix aws_ecs_patterns README having minHealthyPercent in unsupported placed --- packages/aws-cdk-lib/aws-ecs-patterns/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/README.md b/packages/aws-cdk-lib/aws-ecs-patterns/README.md index 82781d8beb8bf..bdd03fc0fc7b8 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/README.md +++ b/packages/aws-cdk-lib/aws-ecs-patterns/README.md @@ -87,7 +87,6 @@ const loadBalancedEc2Service = new ecsPatterns.ApplicationMultipleTargetGroupsEc taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, - minHealthyPercent: 100, targetGroups: [ { containerPort: 80, @@ -184,7 +183,6 @@ const loadBalancedEc2Service = new ecsPatterns.NetworkMultipleTargetGroupsEc2Ser taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, - minHealthyPercent: 100, loadBalancers: [ { name: 'lb1', @@ -227,7 +225,6 @@ const loadBalancedFargateService = new ecsPatterns.NetworkMultipleTargetGroupsFa taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, - minHealthyPercent: 100, loadBalancers: [ { name: 'lb1', @@ -748,7 +745,6 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, - minHealthyPercent: 100, enableExecuteCommand: true, loadBalancers: [ { @@ -821,7 +817,6 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou taskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), }, - minHealthyPercent: 100, enableExecuteCommand: true, loadBalancers: [ { @@ -976,7 +971,6 @@ const securityGroup = new ec2.SecurityGroup(this, 'SG', { vpc }); const scheduledFargateTask = new ecsPatterns.ScheduledFargateTask(this, 'ScheduledFargateTask', { cluster, - minHealthyPercent: 100, scheduledFargateTaskImageOptions: { image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), memoryLimitMiB: 512, From 6af52c817153e4ef8900b0ce680997c139976687 Mon Sep 17 00:00:00 2001 From: Marrick Lip Date: Sat, 12 Oct 2024 23:45:23 +1100 Subject: [PATCH 11/11] fix aws_ecs_patterns README having minHealthyPercent in unsupported placed --- packages/aws-cdk-lib/aws-ecs-patterns/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-ecs-patterns/README.md b/packages/aws-cdk-lib/aws-ecs-patterns/README.md index bdd03fc0fc7b8..0080868830f69 100644 --- a/packages/aws-cdk-lib/aws-ecs-patterns/README.md +++ b/packages/aws-cdk-lib/aws-ecs-patterns/README.md @@ -112,7 +112,6 @@ const loadBalancedFargateService = new ecsPatterns.ApplicationMultipleTargetGrou taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), }, - minHealthyPercent: 100, targetGroups: [ { containerPort: 80,