why NetworkLoadBalancer.fromLookup returning my-load-balancer

0

I am trying to get a network loadbalancer using tags, but not sure why I am getting my-load-balancer-1234567890.us-west-2.elb.amazonaws.com See below code

const nlb = this.getNLBByTag(props);
this.nlbDnsName = nlb.loadBalancerDnsName;

private getNLBByTag(props: ABCDomainVPCStackProps): INetworkLoadBalancer{
        const nlbOptions: NetworkLoadBalancerLookupOptions = {
            loadBalancerTags: {
              component: "apigw",
              application: "abc",
              env: "dev"
            },
        };
        
        return NetworkLoadBalancer.fromLookup(this, `abc-${props.stage}-nlb`, nlbOptions);
    }

Basically it is returning 3 results. First one is "my-load-balancer-1234567890.us-west-2.elb.amazonaws.com" 2nd and 3rd are same which I am looking for, but not sure why it is returning 2nd and 3rd as the same. I have checked only 1 nlb has above tags.

  • Basically vpcLink is creating correctly, but when I am passing the nlbDnsName to the RestAPI then it is failing because it is getting that my-load-balancer DNS name

1 Answer
0

Hello,

From the description, I understand that you are using "NetworkLoadBalancer.fromLookup" in CDK and you are getting the responses of below format for the ".loadBalancerDnsName" method on the obtained object.

my-load-balancer-1234567890.us-west-2.elb.amazonaws.com
<LoadBalancerName>-XXXXXX.elb.<Region>.amazonaws.com

I would like to inform you that I was able to replicate the same in my test environment. Kindly note that this behaviour is expected and occurs because on the first "cdk deploy/synth" if the "cdk.context.json" file is empty and/or does not contain the load-balancer details.

For all the subsequent "cdk deploy", the correct value was obtained as the "cdk.context.json" file would be populated with the required details. You can learn more about "cdk context" at doc[1].

Hence, you can perform "cdk deploy/synth" and check the "cdk.context.json" file for the load-balancer details as shown below:

  "load-balancer:account=XXXXXX: {
    "loadBalancerArn": "arn:aws:elasticloadbalancing:XXXXXX",
    "loadBalancerCanonicalHostedZoneId": "XXXXXX",
    "loadBalancerDnsName": "<LoadBalancerName>-XXXXXX.elb.<Region>.amazonaws.com",
    "vpcId": "vpc-XXXXX",
    "securityGroupIds": [],
    "ipAddressType": "ipv4"
  }

[1] https://docs.aws.amazon.com/cdk/v2/guide/context.html

AWS
Harsha
answered 10 months ago
  • thanks for your response Harsha! I think its not about context, what I am trying to say is the above function is returning 3 NLBs arns as mentioned below arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/network/my-load-balancer/50dc6c495c0c9188 arn:aws:elasticloadbalancing:us-east-2:<dev-account-id>:loadbalancer/net/b72e485999b754299ae2067c2c1b3747/3eb24f395333b0d4 arn:aws:elasticloadbalancing:us-east-2:<dev-account-id>:loadbalancer/net/b72e485999b754299ae2067c2c1b3747/3eb24f395333b0d4

    if you see 2nd and 3rd arn are same, not sure why it is so. Also I have checked by printing the contents of cdk.context.json file after cdk synth in our AWS CDK pipeline and it is returning only 1 NLB(arn:aws:elasticloadbalancing:us-east-2:<dev-account-id>:loadbalancer/net/b72e485999b754299ae2067c2c1b3747/3eb24f395333b0d4).

    So the point is why above function is returning this nlb: arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/network/my-load-balancer/50dc6c495c0c9188 it is not even there in us-west-2 region.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions