feat(ecs-patterns): support a desiredCount of 0 - #38596
Open
marco2216 wants to merge 1 commit into
Open
Conversation
The load balanced ECS patterns rejected `desiredCount: 0` even though `DesiredCount: 0` is valid on the underlying `AWS::ECS::Service` resource, forcing users to an escape hatch to suspend a service or to deploy a service before its container image is ready to start. Only negative values are rejected now. The check also skips unresolved tokens, which previously made a tokenized `desiredCount` throw in three of the four base classes, since number tokens encode as a large negative double. Closes aws#16562 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
marco2216
marked this pull request as ready for review
August 18, 2026 13:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #16562.
Reason for this change
The load balanced ECS patterns reject
desiredCount: 0withYou must specify a desiredCount greater than 0, even thoughDesiredCount: 0is valid on the underlyingAWS::ECS::Serviceresource and is already accepted by theecs.FargateService/ecs.Ec2ServiceL2s.Zero-task services are a real use case, and the linked issue collects several:
The only way to get there today is an escape hatch:
Description of changes
ApplicationLoadBalancedServiceBase,NetworkLoadBalancedServiceBase,ApplicationMultipleTargetGroupsServiceBaseandNetworkMultipleTargetGroupsServiceBase:desiredCountnow only rejects negative values (desiredCount must be greater than or equal to 0, got -1);0is passed through to the service.-1.888e+289), sodesiredCount: someCfnParameter.valueAsNumberused to fail the< 1check and throw in three of the four base classes — the ALB base was the only one that already had the guard. A tokenizeddesiredCountnow reaches the template unchanged.this.desiredCount = props.desiredCount ?? 1(was|| 1), so the deprecateddesiredCountproperty reports0instead of1when0was requested.internalDesiredCount, which is what the services actually use in v2, already carried the raw value.Docs:
desiredCountno longer says "The minimum value is 1", and the README gains a "Run a service without any task" example.Design decisions, flagged per
AGENTS.md:0, and tokens in three of the bases) threw at synth time before this change, so no existing app can synthesize differently.0(QueueProcessingFargateService unable to set desiredCount to zero #4719) was that load balanced services usually scale on CPU/memory, which does nothing at zero tasks. ButdesiredCount: 0is explicit, opt-in, and — per the issue — deliberate; warning on a value the user just asked for would be noise they'd have to acknowledge.ScheduledTaskBase.desiredTaskCountkeeps its>= 1validation. It maps toEcsParameters.TaskCountonAWS::Events::Rule, whose documented minimum is 1, so it is a different case and out of scope here.Describe any new or updated permissions being added
None.
Description of how you validated changes
Unit tests, in
aws-ecs-patterns:desiredCount: 0synthesizesDesiredCount: 0forApplicationLoadBalancedEc2Service,NetworkLoadBalancedEc2Service,ApplicationMultipleTargetGroupsEc2Service,NetworkMultipleTargetGroupsEc2ServiceandApplicationLoadBalancedFargateService(the four tests that asserted the old error are now assertions that0is accepted);-1,-1024) throw the new message;desiredCountreaches the template as{ "Ref": "DesiredCount" }instead of throwing;desiredCountproperty, andinternalDesiredCount, both report0.npx jest aws-ecs-patterns→ 9 suites / 245 tests pass. ESLint clean on every changed file.Integration test:
test/aws-ecs-patterns/test/fargate/integ.alb-fargate-service-desired-count-zero.ts, which deploys a suspended ALB Fargate service and asserts viaECS.describeServicesthatdesiredCountandrunningCountare both 0.Important
I do not have an AWS account to run this repository's integration tests against, so the snapshot was generated with
yarn integ --dry-run --update-on-failedand the test has not been deployed. It needs a maintainer to deploy it before merge — happy for thepr/needs-integration-tests-deploymentlabel to be applied, or I can rerun anything you'd like differently.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license