Skip to content

(ecs): Optional DesiredCount value should be omitted in templates #11951

@johnschultz

Description

@johnschultz

A recent change to ECS Fargate integration with CloudFormation allows for the DesiredCount property to be omitted during both creation and update of an ECS service. If omitted, the minimum scaling value will be used for create operations and the existing count will be preserved in updates unless the count is explicitly set.

Reproduction Steps

Create a FargateService in the most generic way possible. Here's a code snippet from inside our construct:

const cluster = new ecs.Cluster(this, 'Cluster', {});

this.taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {});
this.service = new ecs.FargateService(this, 'Service', {
   cluster: cluster,
   taskDefinition: this.taskDefinition,
});

What did you expect to happen?

I expect the DesiredCount property to be missing from the generated template output.

What actually happened?

The DesiredCount property exists and is set to 1. The CDK's default for the property is being supplied when the DesiredCount is omitted. This is occurring here.

Environment

  • CDK CLI Version : 1.45.0 (Yes, an old version but I've verified the line of code still exists in latest, see link above.)
  • Framework Version: ?
  • Node.js Version: v12.19.0
  • OS : OS X 10.14.6
  • Language (Version): Tested in TypeScript (3.8.3)

Other

This containers roadmap issue contains a great description of the original problem with the DesiredCount field, as well as a brief description of the fix from the ECS team in the comment on November 3rd.

While searching before writing this I cam across #11299, which is similar but a little different in that it tries to solve the problem exclusively in the CDK which is no longer necessary.

Currently, users have to work around this issue by accessing the escape hatches and manually deleting the DesiredCount value. Example below:

const cluster = new ecs.Cluster(this, 'Cluster', {});

this.taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {});
this.service = new ecs.FargateService(this, 'Service', {
   cluster: cluster,
   taskDefinition: this.taskDefinition,
});

const cfnService: CfnService = <CfnService>this.service.node.findChild('Service');
cfnService.addPropertyDeletionOverride('DesiredCount');

If you have any questions you can follow-up with me here or also find me on the Amazon slack.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-ecsRelated to Amazon Elastic ContainerbugThis issue is a bug.effort/mediumMedium work item – several days of effortin-progressThis issue is being actively worked on.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions