Skip to content
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).');
}

Expand Down
27 changes: 27 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/test/ec2/ec2-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading