(elasticloadbalancingv2): Configure cross-zone load balancing for ALB target groups
Describe the feature
Expose ALB's existing ability to turn off cross-zone load balancing for ALB target groups, as described in more detail in the Other Information section.
Use Case
- As an engineer, I want to build a resilient backend service with control over which availability zones my customer requests are routed to, but I can't because CDK hides ALB's ability to control cross-zone load balancing at the target group level.
- I'm always frustrated when CDK does not have feature parity with CloudFormation, especially when, as in this case, there is no usable workaround.
Proposed Solution
The constructor for CDK's ApplicationTargetGroup construct should accept a crossZoneEnabled: boolean flag in the existing constructor props structure, ApplicationTargetGroupProps.
Other Information
Feature supported in ALB
Since November 17, 2022, Application Load Balancers now support turning off cross zone load balancing per target group. See also the Cross-zone load balancing heading on the How Elastic Load Balancing Works user guide page.
Feature supported in CloudFormation
This feature can be used in CloudFormation by setting the following target group attribute:
{
"Key": "load_balancing.cross_zone.enabled",
"Value": "false"
}
under the TargetGroupAttributes property within an AWS::ElasticLoadBalancingV2::TargetGroup resource properties.
No workaround in CDK
In theory, you can workaround this issue in CDK using the CfnTargetGroup.addOverride. However, because adding overrides would entirely replace the values CDK wants to put for the target group attributes, in practice this means adding overrides would force me to replicate CDK's entire logic for target group attributes. This is incredibly frustrating.
Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
CDK version used
2.162.1
Environment details (OS name and version, etc.)
Ubuntu Linux 20.04
Hi @vcschapp , thansk for reaching out.
I see the related issue of configuring cross-zone load balancing false for ALB target groups has been discussed here in detail s-https://github.com/aws/aws-cdk/issues/29866#issuecomment-2062550263
and a corresponding Workaround was also suggested for target groups-https://github.com/aws/aws-cdk/issues/29866#issuecomment-2064577629. There is a PR submissions as well- crossZoneEnabled does not support false for ALB.
Request you to take a look and get back if this does not solve the usecase you are referring to.
@khushail thanks.
The issue you referenced is not related (https://github.com/aws/aws-cdk/issues/31790) and the PR you referenced does not fix the problem (https://github.com/aws/aws-cdk/pull/29907).
In issue #31790, the user is requesting to turn off cross-zone at the ALB level, which is not possible.
The workaround indicated by codypenta@ doesn't work for me in general because, as I mentioned in the main issue text:
In theory, you can workaround this issue in CDK using the CfnTargetGroup.addOverride. However, because adding overrides would entirely replace the values CDK wants to put for the target group attributes, in practice this means adding overrides would force me to replicate CDK's entire logic for target group attributes.
My understanding of the code in CfnResource.addOverride is that there is no way to supplement keys added by CDK. If you use addOverride you are replacing what CDK puts there.
The description for PR https://github.com/aws/aws-cdk/pull/29907 says:
This PR covers the following cases:
...
3/ When
crossZoneEnabledis false withALB, cdk throws an error because ALB does not support disabling it per doc description.
So basically the PR makes CDK throw an exception when you try to turn off cross-zone for ALB at the load balancer level. This is fine, as ALB doesn't support that. But that's not what my issue is about. My issue is about disabling cross-zone at the target group level, which ALB does support, and CloudFormation supports, but CDK does not.
@vcschapp , thanks so much for explaining that so well and getting back.
I understood your point and confirm that its supported by cloudformation as well - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-targetgroup-targetgroupattribute.html#cfn-elasticloadbalancingv2-targetgroup-targetgroupattribute-key
So till it is implemented , as a workaround, this should be achievable with Escape hatches using L1 construct.
I would be marking this as P2 which means it won't be immediately addresed by the team but would be on their radar and for keeping it open for contribution from community as well as from the team as well.
Thanks.
Thanks @khushail, I appreciate the updates.
Btw, it looks like @mazyu36 already has a PR out to potentially fix it!
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.