New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(aws_elasticloadbalancingv2): (error when adding application load balancer to NetworkTargetGroup) #23352
Comments
Hi @Vitaliy-Fanin thanks reaching out. Regarding the error |
I read that post before creating this issue, however .add_target_group() is not a valid function in python code. The closest is .add_target_groups(). It's been almost 2 months, but I saved the stack in case I ever got a response. I just dug into it again. The problem is specifically setting an ALB as the target on the Network Load balancer's target group. If the end of my code looks like below, with #targets=[app_alb2], commented out, everything builds and deploys fine, but the NLB's Target Group does not have a target. If I have that targets line in, I get the error jsii.errors.JSIIError: target.attachToNetworkTargetGroup is not a function.
add_target_groups is fine to add the target group to the listener, but it doesn't have a target inside of it. If I update my code slightly, by NLB_TG.add_target(app_alb2) to the end, I get the same error again.
Bottom line, how do I get the application load balancer set as the target of the network load balancer? Any attempt, whether setting targets=[app_alb2] in the target group creation or by trying to add it as a target after the target group has been created , NLB_TG.add_target(app_alb2), gets me the same jsii.errors.JSIIError: target.attachToNetworkTargetGroup is not a function error. Once the target group has been created, I can go into the console and add it manually without a problem, but we are using these stacks in multiple AWS accounts and that manual step has been forgotten several times already. I'd like for it to be fixed in the code. Am I missing something or is there a bug here? |
Hi @Vitaliy-Fanin thanks for following up. I found some documentation that may help: https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_elasticloadbalancingv2/README.html#defining-an-application-load-balancer Specifically this part of the code example using the AlbTarget helper class, with your target plugged in: listener = nlb.add_listener("listener", port=80)
listener.add_targets("NLB_Target-ALB",
targets=[targets.AlbTarget(app_alb2 80)],
port=80
) I think that upon creating the NLB listener you need to use |
Yes, that worked! Wow. This is the first time I've had to go outside the core library to something else to get something done. I didn't realize there was such a library as aws_elasticloadbalancingv2_targets. I don't know if there is any way to improve the findability of these instructions. I searched a lot to figure this out. Hopefully this ticket will help others too, because this was a frustrating problem for me and there is very little guidance out there about this scenario. Thank you for the help, it is much appreciated. |
Great! Glad to hear that worked, thanks for confirming (also credit to @peterwoodworth for helping me find that solution). I think this issue can be closed now but the topics covered here might be a good candidate for the aws-cdk-examples repository going forward. |
|
Describe the bug
I am trying to create a network load balancer that has an application load balancer as its target. According to this link, this should be possible.
I am able to create the application load balancer and all the actions and targets groups for it. I even figured out how to get around this documented issue.
When I create the NetworkTargetGroup, if I add the alb as a sequence to the targets parameter, I get an error.
jsii.errors.JSIIError: target.attachToNetworkTargetGroup is not a function
Expected Behavior
I should be able to add the application load balancer as a target of the Network Load Balancer.
Current Behavior
jsii.errors.JavaScriptError:
TypeError: target.attachToNetworkTargetGroup is not a function
at NetworkTargetGroup.addTarget (C:....\Temp\jsii-kernel-utIllv\node_modules\aws-cdk-lib\aws-elasticloadbalancingv2\lib\nlb\network-target-group.js:1:2135)
at new NetworkTargetGroup (C:....\Temp\jsii-kernel-utIllv\node_modules\aws-cdk-lib\aws-elasticloadbalancingv2\lib\nlb\network-target-group.js:1:1348)
at NetworkListener.addTargets (C:....\Temp\jsii-kernel-utIllv\node_modules\aws-cdk-lib\aws-elasticloadbalancingv2\lib\nlb\network-listener.js:1:5081)
at C:....\Temp\tmpf0b001vr\lib\program.js:5453:144
at exports.Kernel._ensureSync (C:....\Temp\tmpf0b001vr\lib\program.js:5871:28)
at exports.Kernel.invoke (C:....\Temp\tmpf0b001vr\lib\program.js:5453:73)
at exports.KernelHost.processRequest (C:....\Temp\tmpf0b001vr\lib\program.js:6618:36)
at exports.KernelHost.run (C:....\Temp\tmpf0b001vr\lib\program.js:6592:48)
at Immediate._onImmediate (C:....\Temp\tmpf0b001vr\lib\program.js:6593:46)
at processImmediate (node:internal/timers:466:21)
The above exception was the direct cause of the following exception:
File "C:....\Programs\Python\Python310\lib\site-packages\jsii_runtime.py", line 86, in call
inst = super().call(*args, **kwargs)
File "C:...._app_servers_stack2.py", line 188, in init
app_nlb_listener.add_targets("NLB_Target-ALB",
File "C:....l\Programs\Python\Python310\lib\site-packages\aws_cdk\aws_elasticloadbalancingv2_init_.py", line 11454, in add_targets
return typing.cast("NetworkTargetGroup", jsii.invoke(self, "addTargets", [id, props]))
File "C:....\Programs\Python\Python310\lib\site-packages\jsii_kernel_init_.py", line 148, in wrapped
return recursize_dereference(kernel, fn(kernel, *args, **kwargs))
File "C:....\Programs\Python\Python310\lib\site-packages\jsii_kernel_init.py", line 386, in invoke
response = self.provider.invoke(
File "C:....\Programs\Python\Python310\lib\site-packages\jsii_kernel\providers\process.py", line 362, in invoke
return self._process.send(request, InvokeResponse)
File "C:....\Programs\Python\Python310\lib\site-packages\jsii_kernel\providers\process.py", line 329, in send
raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: target.attachToNetworkTargetGroup is not a function
Reproduction Steps
from aws_cdk import (
Stack,
aws_ec2 as ec2,
aws_iam as iam,
aws_autoscaling as autoscaling,
aws_elasticloadbalancingv2 as elbv2,
Duration
)
from constructs import Construct
class AppServerStack3(Stack):
Possible Solution
No response
Additional Information/Context
I have several spring webservices running on private EC2 instances that are set up in an auto scaling group. We've got API Gateway connected to the EC2 instances through a VPC Link. The VPC Link requires an NLB. The problem is, NLBs don't route traffic based on conditions like ALBs do. So I'm using the NLB to send traffic to the ALB and uses the ALB's conditions parameters to route traffic to the right port of the ASG so that the right web service receives the API call and responds to it.
CDK CLI Version
2.55.0
Framework Version
No response
Node.js Version
v16.17.0
OS
Windows 10
Language
Python
Language Version
Python 3.10.7
Other information
No response
The text was updated successfully, but these errors were encountered: