dongxing2015 2013-06-26 10:16
浏览 81
已采纳

Amazon AWS SDK PHP 2 - 按实例过滤标签?

I have been able to retrieve a full list of tags from all my EC2 instances using the PHP SDK but I'm struggling to filter the results down to a particular instance...

    // Collect instance information
    $sInstanceId = file_get_contents('http://169.254.169.254/latest/meta-data/instance-id'); // 'i-52da5b1f'
    $sAvailabilityZone = file_get_contents('http://169.254.169.254/latest/meta-data/placement/availability-zone'); // 'eu-west-1b'
    $sRegion = preg_replace('/^(.*)([0-9]{1})([a-zA-Z]{1})/', '$1$2', $sAvailabilityZone);

    use Aws\Common\Aws;
    use Aws\Ec2\Command\DescribeTags;
    use Aws\Common\Enum\Region;

    // Set up the global AWS factory
    $oAWS = Aws::factory(array(
            'key'    => CONST_AWS_ACCESS_KEY,
            'secret' => CONST_AWS_SECRET_KEY,
            'region' => $sRegion
    ));

    // Query EC2 for tags
    $oEC2Client = $oAWS->get('ec2');
    $oModel = $oEC2Client->describeTags()->toArray();

I've tried changing the call to describeTags to...

    $oModel = $oEC2Client->describeTags(array(
            "Filters" => array(
                    array("Name" => "resource-id", "Value" => $sInstanceId)
            )
    ))->toArray();

But that seems to make no difference. Could someone shed some light on this for me please?

  • 写回答

1条回答 默认 最新

  • duanque19820925 2013-06-28 00:01
    关注

    The API docs for Ec2Client.describeTags show that Value should actually be Values and should be an array. Try the following:

    $oModel = $oEC2Client->describeTags(array(
        "Filters" => array(
            array("Name" => "resource-id", "Values" => array($sInstanceId))
        )
    ))->toArray();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题