I want to get list of NLB(Network-Load-balancer) in specific region by AWS Java SDK from AWS.
Here is my sample Code:
ElasticLoadBalancingClient loadBalancingClient = ElasticLoadBalancingClient.builder ().credentialsProvider (
StaticCredentialsProvider.create (AwsBasicCredentials.create (
"****", "*****")))
.region (Region.of ("us-east-2")).build ();
DescribeLoadBalancersResponse result = loadBalancingClient.describeLoadBalancers ();
List<LoadBalancerDescription> descriptionList = result.loadBalancerDescriptions ();
System.out.println ("Size: " + descriptionList.size ());
using this procedure i get all classic load-balancer but when i create NLB in AWS. Its give me empty as a result. Means sdk do not detect NLB as a load-balancer. How can i fix this issues ?
To get the Network load balancers, use Elastic Load Balancing v2 Client.
Sample Code:
ElasticLoadBalancingV2Client loadBalancingV2Client = ElasticLoadBalancingV2Client.builder ()
.credentialsProvider (StaticCredentialsProvider.create (
AwsBasicCredentials.create (*****,*****)))
.region (Region.of (*****))
.build ();
DescribeLoadBalancersResponse result = loadBalancingV2Client.describeLoadBalancers ();
This is specify in the documentation: "This reference covers the 2015-12-01 API, which supports Application Load Balancers and Network Load Balancers. The 2012-06-01 API supports Classic Load Balancers."