Search code examples
amazon-web-servicesamazon-ec2aws-php-sdk

AWS EC2 PHP SDK - DescribeInstances With Tag Key and Value


I have EC2 instances tagged with key environment and value production. I am trying to return them using the following:

$result = $ec2_client->describeInstances(array(
    "Filters" => array(
        array(
            "Name" => "tag",
            "Value" => array(
                "environment=production"
            )
        )
    )
));

The above errors out.

How do I specify this method call in the correct manner?


Solution

  • Correct format is:

    $result = $ec2_client->describeInstances(array(
        "Filters" => array(
            array(
                "Name" => "tag:environment",
                "Value" => array(
                    "production"
                )
            )
        )
    ));