aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.41k stars 3.8k forks source link

aws_ecs: Previously turned on managed scaling cannot be disabled #29088

Open JZechy opened 5 months ago

JZechy commented 5 months ago

Describe the bug

If you create a ECS cluster with AsgCapacityProvider with managed scaling enabled, you are not able to disable it any time later.

Once the EneableManagedScaling is set to false, the outputted CloudFormation template does not contain the definition for ManagedScaling property anymore, but this is not causing the CloudFormation to turn off the managed scaling.

Expected Behavior

Setting AsgCapacityProvider.EnableManagedScaling to false should turned off the managing scaling.

Current Behavior

When AsgCapacityProvider.EnableManagedScaling is set to false for the capacity provider, CloudFormation template does not contain ManagedScaling property for AWS::ECS::CapacityProvider anymore. But this missing property doesn't cause the managed scaling to be turned off.

Reproduction Steps

  1. Create a ECS cluster with auto-scale group definition:
Cluster cluster = new(this, "cluster", new ClusterProps
{
    ClusterName = _props.StackName,
    Vpc = vpc,
    ContainerInsights = true
});

cluster.AddAsgCapacityProvider(new AsgCapacityProvider(this, "asg-provider", new AsgCapacityProviderProps
{
    AutoScalingGroup = new AutoScalingGroup(this, "auto-scaling", new AutoScalingGroupProps
    {
        AutoScalingGroupName = _props.StackName,
        Vpc = vpc,
        InstanceType = InstanceType.Of(InstanceClass.T3, InstanceSize.NANO),
        MinCapacity = 0,
        MaxCapacity = 5,
        MachineImage = EcsOptimizedImage.AmazonLinux2023(),
        InstanceMonitoring = Monitoring.DETAILED,
        SecurityGroup = ConstructSecurityGroup(vpc),
        Role = CreateInstanceRole()
    }),
    CapacityProviderName = _props.StackName
}), new AddAutoScalingGroupCapacityOptions());
  1. After cluster is deployed, change AsgCapacityProvider property EnableManagedScaling to false.

Possible Solution

The ManagedScaling property should be probably still present but with Status set to DISABLED.

Additional Information/Context

Problem occurs only when updating existing cluster. If you create new cluster with scaling disabled, it is created in correct way.

CDK CLI Version

2.126.0

Framework Version

2.124.0

Node.js Version

20.10.0

OS

Fedora 39

Language

.NET

Language Version

8

Other information

No response

pahud commented 5 months ago

Sounds like it only happens when updating the existing cluster. I am not sure if we should explicitly set it as false when undefined but we appreciate your workaround here.

smvgau commented 1 month ago

Bumping this because this affects me as well. It's a surprising effect because the default examples within CDK describe using the capacity provider and enabling this, but no where does it describe how permanent this effect currently is.

Note this is also a problematic issue because allowing for AWS to manage this, allows for conflicting rules for an ASG to have, causing thrashing.