aws_elasticloadbalancingv2: using from_lookup falsely assumes Dual Stack
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When running this block of code:
Example 1
```
nlb = elbv2.NetworkLoadBalancer.from_lookup(
self,
id='nlb',
load_balancer_arn=env_data['nlb_arn']
)
print(f"IP_ADDRESS_TYPE: {nlb.ip_address_type}")
listener = nlb.add_listener(
id='listener',
port=nlb_listener_port,
protocol=elbv2.Protocol.UDP
)
```
The print statement shows DUAL_STACK and not IPV4
```
IP_ADDRESS_TYPE: IpAddressType.DUAL_STACK
```
When in reality ... This is not a dual stack NLB.
```
aws elbv2 describe-load-balancers --load-balancer-arns arn:aws:elasticloadbalancing:REGION:ACCOUNT:loadbalancer/net/NLB_NAME | jq -r .LoadBalancers[0].IpAddressType
ipv4
```
### Expected Behavior
Expected behavior is for the `.from_lookup()` function to correctly determine the `ip_address_type` instead of assume DUAL_STACK, and then properly attach the `add_listener()` as requested without errors.
NOTE: When using `.from_network_load_balancer_attributes()`, it works fine.
### Current Behavior
Because the returned INetworkLoadBalancer does not actually grab the truthiness of ip_address_type, but assumes it to be DUAL_STACK, the CDK stack FAILS to add the listener with this message:
```
RuntimeError: Error: UDP or TCP_UDP listeners cannot be added to a dualstack network load balancer.
```
NOTE: When using `.from_network_load_balancer_attributes()`, it works fine.
### Reproduction Steps
Create an NLB in another stack or manually, and save the ARN into an SSM Parameter. Read in the parameter in a CDK stack and use from_lookup() to get an INetworkLoadBalancer object and add_listener() to add a UDP listener.
```
nlb_arn_ssm = ssm.StringParameter.from_string_parameter_name(
self,
id="nlb-arn-ssm",
string_parameter_name="test_nlb_arn")
nlb = elbv2.NetworkLoadBalancer.from_lookup(
self,
id='nlb',
load_balancer_arn=nlb_arn_ssm.string_value
)
print(f"IP_ADDRESS_TYPE: {nlb.ip_address_type}")
nlb_listener_port = 7777
listener = nlb.add_listener(
id='listener',
port=nlb_listener_port,
protocol=elbv2.Protocol.UDP
)
```
### Possible Solution
When pulling in information about the NLB using the ARN, pull in the ip_address_type as well using `describe-load-balancers` ?
### Additional Information/Context
_No response_
### CDK CLI Version
2.142.1 (build ed4e152)
### Framework Version
python
### Node.js Version
v18.19.0
### OS
macOs 14.5 (23F79)
### Language
Python
### Language Version
Python 3.12.4
### Other information
```
jsii.errors.JavaScriptError:
@jsii/kernel.RuntimeError: Error: UDP or TCP_UDP listeners cannot be added to a dualstack network load balancer.
at Kernel._Kernel_ensureSync (/private/var/folders/qz/dgx8s7357r9bfpywd3q336d80000gn/T/tmp_515if_3/lib/program.js:10502:23)
at Kernel.invoke (/private/var/folders/qz/dgx8s7357r9bfpywd3q336d80000gn/T/tmp_515if_3/lib/program.js:9866:102)
at KernelHost.processRequest (/private/var/folders/qz/dgx8s7357r9bfpywd3q336d80000gn/T/tmp_515if_3/lib/program.js:11707:36)
at KernelHost.run (/private/var/folders/qz/dgx8s7357r9bfpywd3q336d80000gn/T/tmp_515if_3/lib/program.js:11667:22)
at Immediate._onImmediate (/private/var/folders/qz/dgx8s7357r9bfpywd3q336d80000gn/T/tmp_515if_3/lib/program.js:11668:46)
at process.processImmediate (node:internal/timers:476:21)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/timothywelch/sharpen/src-openvxi/cdk/app.py", line 99, in
application_stack = ApplicationStack(
^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/lib/application.py", line 136, in __init__
self.ecs = _ecs(
^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/lib/ecs.py", line 964, in __init__
listener = nlb.add_listener(
^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 13826, in add_listener
return typing.cast("NetworkListener", jsii.invoke(self, "addListener", [id, props]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/jsii/_kernel/__init__.py", line 149, in wrapped
return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/jsii/_kernel/__init__.py", line 399, in invoke
response = self.provider.invoke(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/jsii/_kernel/providers/process.py", line 380, in invoke
return self._process.send(request, InvokeResponse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/timothywelch/sharpen/src-openvxi/cdk/venv/lib/python3.12/site-packages/jsii/_kernel/providers/process.py", line 342, in send
raise RuntimeError(resp.error) from JavaScriptError(resp.stack)
RuntimeError: Error: UDP or TCP_UDP listeners cannot be added to a dualstack network load balancer.
Subprocess exited with error 1
```
Contributor guide
Research direction
The relevant entry points are NetworkLoadBalancer.from_lookup and from_network_load_balancer_attributes; compare how each obtains ip_address_type, then trace the describe-load-balancers lookup described in the issue. Re-run the Python reproduction with an IPv4 NLB and verify that lookup reports IPV4 and permits the UDP listener without the dual-stack error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100