-
Notifications
You must be signed in to change notification settings - Fork 4k
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] Add support for SubnetMapping to Network Load Balancer #9696
Comments
hmmm not sure if it's even worth it... This does the job:
|
Also interested in this for the ability to specify the private IPv4 of a NetworkLoadBalancer - see PrivateIPv4Address |
@michaelwiles Thanks for the example, it helped me! It doesn't quite work as written though:
This error is an example of why it's nice to have higher-level constructs for these kinds of things. |
See also: #7424 |
@cfclrk I encountered the same error and this worked for me. elastic_ip = CfnEIP(self, "EIP")
network_load_balancer = NetworkLoadBalancer(
self,
"NetworkLoadBalancer",
vpc=cluster.vpc,
internet_facing=True,
)
cfn_nlb = network_load_balancer.node.default_child
subnet_mapping = CfnLoadBalancer.SubnetMappingProperty(
subnet_id=cluster.vpc.public_subnets[0].subnet_id,
allocation_id=elastic_ip.attr_allocation_id,
)
cfn_nlb.subnet_mappings = [subnet_mapping]
# i think the higher-level NetworkLoadBalancer construct sets subnets on the lower-level CfnLoadBalancer construct
# clearing subnets on the lower-level construct allowed me to add the subnet mapping without issue
cfn_nlb.subnets = None Credit to @michaelwiles for the solution! |
Many thanks to @josh-wiley for the working example. Here extended to also set a fixed IPv6 address on a dualstack NLB: eip = CfnEIP(self, "ElasticIP")
self.nlb = NetworkLoadBalancer(
self,
"LoadBalancer",
vpc=self.vpc,
internet_facing=True
)
cfn_lb: CfnLoadBalancer = self.nlb.node.default_child
cfn_lb.ip_address_type = "dualstack"
cfn_subnet: CfnSubnet = self.vpc.public_subnets[0].node.default_child
ipv6_network = Fn.select(0, cfn_subnet.attr_ipv6_cidr_blocks)
ipv6_prefix = Fn.select(0, Fn.split("::", ipv6_network))
# The answer to what the last part of the IPv6 address should be is obviously 42
ipv6_addr = Fn.join("::", [ipv6_prefix, "42"])
subnet_mapping = CfnLoadBalancer.SubnetMappingProperty(
subnet_id=self.vpc.public_subnets[0].subnet_id,
allocation_id=eip.attr_allocation_id,
i_pv6_address=ipv6_addr
)
cfn_lb.subnet_mappings = [subnet_mapping]
cfn_lb.subnets = None |
I'm trying to set a pair of Elastic IPs as the public facing addresses for a NetworkLoadBalancer object and running into issues. The
Code:
I've found references to CDK wanting a tag of |
This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue. |
Add Subnet mappings to the Network Load Balancer construct
Use Case
We have a network load balancer and we need it on a static ip thus we hook up an elastic ip to this network load balancer.
This is possible via the console and it also seems possible via the SubnetMapping property on network load balancer in cloudformation.
Proposed Solution
To add that subnet mapping construct as a property on the NetworkLoadBalancer construct.
Other
I suspect that in the mean time I can use the CfnLoadBalancer either as the primary construct or fetch it and change it after creation of the cdk network load balancer.
Not sure if I should try this or focus on adding the mapping to the network load balancer...
There is already an available SubnetMappingProperty which I'd assume we'd replicate in the primary world (it's in the Cfn world and thus potentially not stable).
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: