We have 2 proxy servers which we will like to be front-ended with NLB. I am using AWS-CDK (python) for creating via CloudFormation. I am trying to register ec2 as either instanceid or instance documentation link. I am hoping if someone can provide a link to an example or help to fix the code below.
from aws_cdk import core
from aws_cdk import aws_elasticloadbalancingv2 as _elbv2
from aws_cdk import aws_ec2 as _ec2
from aws_cdk import aws_elasticloadbalancingv2_targets as _elbv2target
class EnergyelbStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
vpc = _ec2.Vpc.from_lookup(
self,
"vpc",
vpc_id = "vpc-0exxxb36c"
)
ec2a = "i-0xxx7f31"
ec2b = "i-0xxx80b1"
tg = _elbv2target.InstanceIdTarget(
instance_id = [ec2a],
port = 3130
)
nlb = _elbv2.NetworkLoadBalancer(
self,
"NetworkLB",
vpc=vpc,
internet_facing=False,
#attach_to_network_target_group = tg
)
# Add a listener on a particular port.
listener = nlb.add_listener(
"Listener",
protocol = "tcp",
port=3130
)
target_group = listener.add_targets("ProxyServer",
port=3130,
targets=tg
)
listener.attach_to_network_target_group(tg)
Here is the updated code that worked. It provided by Alban Esc @DaWyz gitter.com/aws-cdk