aws java sdk describeloadbalancersresult返回空响应

lvjbypge  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(164)

aws java apidescribeloadbalancersresult在提供正确的区域代码和aws凭据后返回空的负载平衡器描述。aws中有负载平衡器,它们通过cli返回

public void getELB(String accessKey, String secretKey, String region, String... elbids) throws Exception {
        AmazonElasticLoadBalancingClient amazonElasticLoadBalancingClient = new EC2Client().getELBClient(accessKey,
                secretKey, region);
        DescribeLoadBalancersResult describeLoadBalancersResult = amazonElasticLoadBalancingClient.describeLoadBalancers();
        System.out.println(describeLoadBalancersResult);
        List<LoadBalancerDescription> balancerDescriptions = describeLoadBalancersResult.getLoadBalancerDescriptions();
        for (Iterator iterator = balancerDescriptions.iterator(); iterator.hasNext();) {
            LoadBalancerDescription loadBalancerDescription = (LoadBalancerDescription) iterator.next();
            System.out.println(loadBalancerDescription);

        }
    }

it输出

{LoadBalancerDescriptions: [],}

下面是创建 AmazonElasticLoadBalancingClient ```
public AmazonElasticLoadBalancingClient getELBClient(String accessKey, String secretKey, String region) throws Exception {
AWSCredentialsProvider provider;
if (accessKey != null && secretKey != null) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
provider = new StaticCredentialsProvider(credentials);
} else {
provider = new DefaultAWSCredentialsProviderChain();
}
AmazonElasticLoadBalancingClient client = new AmazonElasticLoadBalancingClient(provider).withRegion(Regions.fromName(region));
ClientConfiguration configuration = new ClientConfiguration();
configuration.setProtocol(Protocol.HTTPS);
return client;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题