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.66k stars 3.92k forks source link

aws-cdk-lib.aws_elasticloadbalancingv2: Invalid property for NLB "NetworkWeightedTargetGroup" #23922

Open lucaspellucci opened 1 year ago

lucaspellucci commented 1 year ago

Describe the issue

There is no such thing as Weighted Target Group for NLB, at this moment this feature is exclusive for ALB.

Trying to build a NLB using more than one target group will retutn the error below:

"You cannot specify multiple target groups in a single action with a load balancer of type 'network' (Service: ElasticLoadBalancingV2, Status Code: 400"

Links

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.NetworkWeightedTargetGroup.html

pahud commented 1 year ago

Hi @lucaspellucci

Can you share some sample code so we can run it in our environment for reproduction?

tlee9595 commented 1 year ago

@pahud

where targetGroupOne and targetGroupTwo is of type NetworkTargetGroup, and loadBalancer is a NetworkLoadBalancer

this.loadBalancer.addListener('Listener', { defaultAction: NetworkListenerAction.weightedForward([ { targetGroup: targetGroupOne, weight: 5 }, { targetGroup: targetGroupTwo, weight: 95 }, ]), port: 8080 });

You will get a error when you compile, but if you look at NetworkLoadBalancer.addListener, it takes BaseNetworkListenerProps, which contains NetworkListenerAction that allows weightedForward to be used even though NLB doesn't support it.

lucaspellucci commented 1 year ago

Thanks, tlee9595, my code snipped is exactly the same.

Also, I want to leave this from the CloudFormation documentation here:

image

antonioshondroulis-saltsecurity commented 3 months ago

just confirming this still doesn't work, I was testing with different weights but same defaultAction on listener. There's no support for weightedForward as of today, it was also specified as a side note from AWS support for a different purpose, as differences with ALB.

So not sure if the documentation of NLB listener for CDK should be so explicit:

Screenshot 2024-08-05 at 6 31 38 PM