Pergunta

If I already have an AWS ELB and want to get a handle to it using the java SDK and print the list of EC2 instances connected to it, what's the best way to do it?

I see a lot of examples on how to create an ELB using the api but nothing about getting the handle.

Thanks!

Foi útil?

Solução

I'm fairly certain if you pass the ELB that you are trying to get the instances from to DescribeLoadBalancers will give you the information you need.

Outras dicas

I ended up using the following snippet:

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonElasticLoadBalancingClient elb = new AmazonElasticLoadBalancingClient(credentials);
    DescribeLoadBalancersResult lbs = elb.describeLoadBalancers();

    List<LoadBalancerDescription> descriptions = lbs.getLoadBalancerDescriptions();
    for (LoadBalancerDescription loadBalancerDescription : descriptions) {
        System.out.println("Name: " + loadBalancerDescription.getLoadBalancerName());
        System.out.println("DNS Name: " + loadBalancerDescription.getDNSName());
        System.out.println("Instances:");

        for (Instance instance : loadBalancerDescription.getInstances()) {
            System.out.println("\t" + instance.getInstanceId());
        }
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top