Search code examples
phpamazon-web-servicesaws-sdkamazon-elbelastic-load-balancer

AWS SDK for PHP - No load balancers are showing


I am using the AWS SDK for PHP to query a load balancer for all of its healthy instances. I tried using the describeInstanceHealth method to get all of the healthy instances from my ELB, only to find that it said there was no active load balancer with the name I supplied.

I then decided to use describeLoadBalancers to see what name it used internally, only to find that the function is returning no load balancers at all. I have 3 active load balancers that are being used as I type this.

Here is the relevant portion of my code:

<?php
require 'aws/aws-autoloader.php';

use Aws\ElasticLoadBalancing\ElasticLoadBalancingClient;
...
$client = ElasticLoadBalancingClient::factory([
    'key'    => env('ACCESS_KEY'),
    'secret' => env('SECRET'),
    'region' => env('REGION')
]);

$result = $client->describeLoadBalancers();
var_dump($result);

The output I get is the following:

object(Guzzle\Service\Resource\Model)#106 (2) { 
    ["structure":protected]=> NULL ["data":protected]=> array(2) {
        ["LoadBalancerDescriptions"]=> array(0) { } 
        ["ResponseMetadata"]=> array(1) { 
            ["RequestId"]=> string(36) "e6e7b0a4-7880-11e7-bb72-995ab0ed2a69" 
        }
    }
}

Note that the LoadBalancerDescriptions key has an empty array, when it should contain a description of all active load balancers.

My guess is that something is not configured correctly with the IAM roles and my user is not able to see the load balancers, but I don't know of a way to attach the user/access key that I am using to the load balancers.

How can I make the load balancers visible to the API calls I am making?

I am using PHP 5.6.31.


Solution

  • It turns out ELB supports two types of load balancers: Classic and Application. The AWS SDK V1 does not support application load balancers. I had to upgrade the SDK and use describeTargetHealth to get the instance IDs for each instance in the load balancer.