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.38k stars 3.78k forks source link

[aws_elasticloadbalancingv2]: Target Group 'slowStart' option can't be disabled #29437

Closed frfavoreto closed 3 months ago

frfavoreto commented 4 months ago

Describe the bug

When you set slowStart attribute on a Target Group it sets this property correctly in the CFN template:

const targetGroup = httpListener.addTargets('myTG', {
      protocol: elbv2.ApplicationProtocol.HTTP,
      slowStart: cdk.Duration.seconds(40),
    });

Template:

"TargetGroup52DC4313": {
   "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
   "Properties": {
   .
   .
   .
    "TargetGroupAttributes": [
     {
      "Key": "slow_start.duration_seconds",
      "Value": "40"
     }

But when trying to remove this setting by just removing slowStart attribute, CDK removes the synthesized attribute from the CFN template but the actual ElbV2 Target Group resource is not changed.

In the docs the default value would be set to "0" (disabled) but it doesn't accept anything outside the 30-900 range:

Error: Slow start duration value must be between 30 and 900 seconds.

The only way to disable it is by directly changing the Target Group Attributes from AWS Console/CLI.

Expected Behavior

Slow Start attribute removed from the ElbV2 Target Group by either removing 'slowStart' option from the construct's properties or by setting it to "0" (slowStart: cdk.Duration.seconds(0))

Current Behavior

Slow Start attribute can not be removed from CDK. Not possible to set it to "0".

Reproduction Steps

1 - Create ALB, Listener and Target Group (with slowStart property set)

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

    const alb = new elbv2.ApplicationLoadBalancer(this, 'myALB', {
      vpc: vpc,
    });

    const httpListener = alb.addListener('myListener-http', { 
      protocol: elbv2.ApplicationProtocol.HTTP,
    });

    const targetGroup = httpListener.addTargets('myTG', {
      protocol: elbv2.ApplicationProtocol.HTTP,
      slowStart: cdk.Duration.seconds(40),
    });

2 - Try removing 'slowStart' property and it deploys successfully, but Target Group resource keeps it enabled. Or try to set it to "0" and CDK does not allow it.

Possible Solution

Allow "0" in the range for cdk.Duration.seconds() values and implicitly synthesize the Target Group resource with this as default when slowStart attribute is omited (if previously enabled):

"TargetGroupAttributes": [ { "Key": "slow_start.duration_seconds", "Value": "0" }

Additional Information/Context

No response

CDK CLI Version

All supported versions, including latest 2.132.0

Framework Version

No response

Node.js Version

16

OS

Mac

Language

TypeScript

Language Version

No response

Other information

No response

pahud commented 4 months ago

According to the doc:

slow_start.duration_seconds - The time period, in seconds, during which a newly registered target receives an increasing share of the traffic to the target group. After this time period ends, the target receives its full share of traffic. The range is 30-900 seconds (15 minutes). The default is 0 seconds (disabled).

I think we should fix it here to allow explicitly 0 to disable it.

https://github.com/aws/aws-cdk/blob/5b910f0d61d4adae38788f7f16ccdae6cb214057/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts#L333-L335

msambol commented 4 months ago

I'll take this.

github-actions[bot] commented 3 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.