From 423602699e1ef1dc87f8080f7de5930f14ee1ba5 Mon Sep 17 00:00:00 2001 From: RadhaKrishnan Pachyappan Date: Sun, 14 Jun 2026 00:37:44 +0530 Subject: [PATCH] fix(ecs): suppress shouldUseCircuitBreaker warning for DAEMON services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ECS deployment circuit breaker is desiredCount-based (threshold = 0.5 × desiredCount) and is not applicable to DAEMON scheduling strategy services, which have no desiredCount. BaseService was emitting a false-positive shouldUseCircuitBreaker warning for daemon services because the guard only checked !circuitBreaker && isEcsDeploymentController without accounting for the scheduling strategy. Fix: skip the warning when schedulingStrategy is DAEMON, consistent with how CDK already special-cases daemon mode for desiredCount validation, minHealthyPercent, and placement strategy checks. Fixes #38102 Signed-off-by: Radhakrishnan Pachyappan --- .../aws-ecs/lib/base/base-service.ts | 3 ++- .../aws-ecs/test/ec2/ec2-service.test.ts | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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 594f837725164..376783bda8fee 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 @@ -1013,8 +1013,9 @@ export abstract class BaseService extends Resource Annotations.of(this)._addTrackableError(lit`CircuitBreakerRequiresEcsController`, 'Deployment circuit breaker requires the ECS deployment controller.'); } - if (!props.circuitBreaker && this.isEcsDeploymentController) { + if (!props.circuitBreaker && this.isEcsDeploymentController && additionalProps?.schedulingStrategy !== 'DAEMON') { // If we *could* use a circuit breaker, then let's recommend users to do so. It makes detecting errors sooo much faster. + // The circuit breaker is not applicable to DAEMON services (its threshold is desiredCount-based and daemon services have no desiredCount). Annotations.of(this).addWarningV2('@aws-cdk/aws-ecs:shouldUseCircuitBreaker', 'Enable the \'circuitBreaker\' property to trigger a quicker deployment failure if tasks are failing to come start (without this setting deployments may take up to 3 hours to fail).'); } 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 f7d92e4838fb6..97eb377414939 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 @@ -94,6 +94,33 @@ describe('ec2 service', () => { } }); + test('does not suggest circuitBreaker for DAEMON scheduling strategy services', () => { + // GIVEN + const app = new cdk.App(); + const stack = new cdk.Stack(app, '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'); + + taskDefinition.addContainer('web', { + image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), + memoryLimitMiB: 512, + }); + + new ecs.Ec2Service(stack, 'Ec2Service', { + cluster, + taskDefinition, + daemon: true, + // no circuitBreaker — warning should NOT fire because daemon services + // have no desiredCount and the circuit breaker threshold is desiredCount-based + }); + + // THEN + const warnings = flattenMeta(app.synth().getStackByName('Stack').metadata)['/Stack/Ec2Service']?.['aws:cdk:warning']; + expect(warnings ?? []).not.toContainEqual(expect.stringContaining('Enable the \'circuitBreaker\' property')); + }); + [false, undefined].forEach((value) => { test('set cloudwatch permissions based on falsy feature flag when no cloudwatch log configured', () => { // GIVEN