【问题标题】:Amazon AWS, Creating a name tag for ec2 instance using PHP SDK 2Amazon AWS,使用 PHP SDK 2 为 ec2 实例创建名称标签
【发布时间】:2014-01-04 07:42:38
【问题描述】:

我正在使用最新版本 (2) 的 SDK for php。下面是为现有实例分配名称标签的 sn-p 代码:

try {
    $result = $ec2->createTags(array(
        'Resources' => array($instanceid),
        'Tags' => array(
            'Name' => 'PWC_cwc'),
    )); 
} catch (Exception $e) {
    die("Failed to create tag name: ".$e."<br>");
}

输出:

无法创建标签名称:异常 'Guzzle\Service\Exception\ValidationException' 并在 /Users/harry/Documents/workspace/ 中显示消息“验证错误:[Tags][Name][Tag] 必须是对象类型” BigData/vendor/guzzle/guzzle/src/Guzzle/Service/Command/AbstractCommand.php:394 堆栈跟踪:#0

我猜我传递参数的方式有问题,但就是想不出正确的方法

createTags 方法的 API 链接在这里:http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ec2.Ec2Client.html#_createTags

【问题讨论】:

    标签: php amazon-web-services amazon-ec2


    【解决方案1】:

    您必须指定每个标签的“键”和“值”。

    $args = array(
        'DryRun' => False,
        'Resources' => array($resource),
        'Tags' => array(
            array(
            'Key' => 'firstkey',
            'Value' => $firstkeyvalue),
            array(
            'Key' => 'secondkey',
            'Value' => $secondkeyvalue),
            array(
            'Key' => 'thirdkey',
            'Value' => $thirdkeyvalue)
            ));
    $response = $ec2->createTags($args);
    

    【讨论】:

      【解决方案2】:

      试试这个:

      $result = $ec2->createTags(array(
          'Resources' => array($instanceid),
          'Tags' => array(
              'Tag' => array(
                 'Key' => '<key>',
                 'Value' => '<value>'
             )
          )
      ));
      

      您需要在 'Tags' 数组中包含一个 'Tag' 数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        • 2017-11-11
        • 2016-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多