Skip to content

Commit

Permalink
docs(ecs-patterns): remove references to REMOVE_DEFAULT_DESIRED_COUNT (
Browse files Browse the repository at this point in the history
…#29344)

### Issue # (if applicable)

Closes # 29325

### Reason for this change

The `REMOVE_DEFAULT_DESIRED_COUNT` feature flag is always enabled in CDKv2, and throws builds errors if explicitly set. The `ecs-patterns`  docs still reference it as "opt-in", which is misleading.

 Ref: [list of deprecated feature flags for v2](https://github.com/aws/aws-cdk/blob/3cbad4a2164a41f5529e04aba4d15085c71b7849/packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md?plain=1#L145)

See [Issue 29325](#29325) for a sample build error when trying to follow the current example code in docs for enabling the flag.

I did NOT remove the actual conditionals in the construct code, that check the (now always true) feature flag. This is dead code that can probably be removed as a chore task. My focus here was on removing friction for developers reading documentation.

### Description of changes

I removed the section in the README of `ecs-patterns` showing how to manually enable this flag. I also updated the default cases in docstrings that referenced the flag.

### Description of how you validated changes

Doc change only, no functional changes. I did double check that the defaults described in the docstrings (when the feature flag is enabled) were still accurate.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jlizen authored Mar 4, 2024
1 parent b19f822 commit 704f596
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 62 deletions.
50 changes: 0 additions & 50 deletions packages/aws-cdk-lib/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,56 +921,6 @@ const scheduledFargateTask = new ecsPatterns.ScheduledFargateTask(this, 'Schedul
});
```

### Use the REMOVE_DEFAULT_DESIRED_COUNT feature flag

The REMOVE_DEFAULT_DESIRED_COUNT feature flag is used to override the default desiredCount that is autogenerated by the CDK. This will set the desiredCount of any service created by any of the following constructs to be undefined.

* ApplicationLoadBalancedEc2Service
* ApplicationLoadBalancedFargateService
* NetworkLoadBalancedEc2Service
* NetworkLoadBalancedFargateService
* QueueProcessingEc2Service
* QueueProcessingFargateService

If a desiredCount is not passed in as input to the above constructs, CloudFormation will either create a new service to start up with a desiredCount of 1, or update an existing service to start up with the same desiredCount as prior to the update.

To enable the feature flag, ensure that the REMOVE_DEFAULT_DESIRED_COUNT flag within an application stack context is set to true, like so:

```ts
declare const stack: Stack;
stack.node.setContext(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT, true);
```

The following is an example of an application with the REMOVE_DEFAULT_DESIRED_COUNT feature flag enabled:

```ts nofixture
import { Construct } from 'constructs';
import { App, Stack } from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ecsPatterns from 'aws-cdk-lib/aws-ecs-patterns';
import * as cxapi from 'aws-cdk-lib/cx-api';
import * as path from 'path';

class MyStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);

this.node.setContext(cxapi.ECS_REMOVE_DEFAULT_DESIRED_COUNT, true);

const vpc = new ec2.Vpc(this, 'VPC', {
maxAzs: 2,
});

new ecsPatterns.QueueProcessingFargateService(this, 'QueueProcessingService', {
vpc,
memoryLimitMiB: 512,
image: new ecs.AssetImage(path.join(__dirname, '..', 'sqs-reader')),
});
}
}
```

### Deploy application and metrics sidecar

The following is an example of deploying an application along with a metrics sidecar container that utilizes `dockerLabels` for discovery:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ export interface ApplicationLoadBalancedServiceBaseProps {
* The desired number of instantiations of the task definition to keep running on the service.
* The minimum value is 1
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* @default - The default is 1 for all new services and uses the existing service's desired count
* when updating an existing service.
*/
readonly desiredCount?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export interface ApplicationMultipleTargetGroupsServiceBaseProps {
/**
* The desired number of instantiations of the task definition to keep running on the service.
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* @default - The default is 1 for all new services and uses the existing service's desired count
* when updating an existing service.
*/
readonly desiredCount?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export interface NetworkLoadBalancedServiceBaseProps {
* The desired number of instantiations of the task definition to keep running on the service.
* The minimum value is 1
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* @default - The default is 1 for all new services and uses the existing service's desired count
* when updating an existing service.
*/
readonly desiredCount?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export interface NetworkMultipleTargetGroupsServiceBaseProps {
* The desired number of instantiations of the task definition to keep running on the service.
* The minimum value is 1
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the default is 1 for all new services and uses the existing services desired count
* @default - The default is 1 for all new services and uses the existing service's desired count
* when updating an existing service.
*/
readonly desiredCount?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export interface QueueProcessingServiceBaseProps {
/**
* The desired number of instantiations of the task definition to keep running on the service.
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is 1;
* if true, the minScalingCapacity is 1 for all new services and uses the existing services desired count
* @default - The minScalingCapacity is 1 for all new services and uses the existing services desired count
* when updating an existing service.
* @deprecated - Use `minScalingCapacity` or a literal object instead.
*/
Expand Down Expand Up @@ -128,14 +127,14 @@ export interface QueueProcessingServiceBaseProps {
/**
* Maximum capacity to scale to.
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is (desiredTaskCount * 2); if true, the default is 2.
* @default 2
*/
readonly maxScalingCapacity?: number;

/**
* Minimum capacity to scale to.
*
* @default - If the feature flag, ECS_REMOVE_DEFAULT_DESIRED_COUNT is false, the default is the desiredTaskCount; if true, the default is 1.
* @default 1
*/
readonly minScalingCapacity?: number;

Expand Down

0 comments on commit 704f596

Please sign in to comment.