1

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

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

输出:

无法在 /Users/harry/Documents/workspace/BigData/vendor 中创建标签名称:异常“Guzzle\Service\Exception\ValidationException”,并带有消息“验证错误:[Tags][Name][Tag] 必须是对象类型” /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

4

2 回答 2

4

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

$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);
于 2014-01-03T23:42:38.000 回答
3

尝试这个:

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

您需要在“标签”数组中有一个“标签”数组。

于 2013-06-19T04:46:59.183 回答