aws / aws/aws-cdk

QueueProcessingFargateServiceProps Cooldown property is not used when using a CPU Target Utilization scaling policy.

Open
#31,172 3 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-ecs-patterns bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

QueueProcessingFargateServiceProps Cooldown property is not used when using a CPU Target Utilization scaling policy.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

When creating a QueueProcessingFargateService and when using CPU Target Utilization, the cooldown provided should override the default (300 seconds) and be added to scale-in and scale-out.

### Current Behavior

Currently, when creating a QueueProcessingFargateService and using CPU Target Utilization, the Cooldown property is not used, and the default of 300 seconds is used for scale-in and scale-out.

### Reproduction Steps

```
var service = new QueueProcessingFargateService(this, "EventsHandler", new QueueProcessingFargateServiceProps
{
ContainerName = "EventsHandler",
Cluster = this.Cluster,
Image = // image
Environment = new Dictionary
{
// environment
},
MaxScalingCapacity = 4,
MinScalingCapacity = 1,
CpuTargetUtilizationPercent = 75,
Cooldown = Duration.Seconds(120),
Queue = _eventsQueue,
LogDriver = logDriver,
HealthCheck = healthCheck,
});
```

1. Create a basic QueueProcessingFargateService with CpuTargetUtilizationPercent and Cooldown set
2. Deploy the resource to AWS
3. Either pull the resource scaling policy with the CLI or view it in the ECS dashboard
4. Note that the scale-in and scale-out cooldown times are not set.

### Possible Solution

BaseService contains `AutoScaleTaskCount(EnableScalingProps props)` which works with `ApplicationLoadBalancedFargateService`, but appears not to work with Queue Processors because there is already some default scaling created under the hood. Allowing the use of AutoScaleTaskCount would be nice because it seems a bit more flexible:

```
var autoscalingGroup = service.Service.AutoScaleTaskCount(new EnableScalingProps
{
MinCapacity = _props.Configuration.ECSMinCapacity,
MaxCapacity = _props.Configuration.ECSMaxCapacity,
});

autoscalingGroup.ScaleOnCpuUtilization("cpuScaling", new CpuUtilizationScalingProps
{
TargetUtilizationPercent = 60,
ScaleInCooldown = Duration.Seconds(300),
ScaleOutCooldown = Duration.Seconds(60),
});
```

Currently when attempting to use AutoScaleTaskCount with a QueueProcessingFargateService, we get this during the synth:

`Unhandled exception. System.Exception: Error: AutoScaling of task count already enabled for this service`

### Additional Information/Context

![image](https://github.com/user-attachments/assets/65e28970-024d-4a47-856c-e5a62d06e972)

### CDK CLI Version

2.130.0

### Framework Version

2.130.0

### Node.js Version

21.2.0

### OS

Linux

### Language

.NET

### Language Version

8

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the QueueProcessingFargateService CPU target utilization scaling path and compare it with BaseService.AutoScaleTaskCount and EnableScalingProps, which the issue identifies as relevant entry points. Reproduce the configuration with CpuTargetUtilizationPercent and Cooldown, then inspect the synthesized or deployed scaling policy; done means the provided cooldown is applied to both scale-in and scale-out instead of the 300-second default.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.