[英]Amazon AWS, Creating a name tag for ec2 instance using PHP SDK 2
我正在使用PHP的最新版本(2)的SDK。 以下是用於為現有實例分配名稱標簽的代碼段:
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
您必須指定每個標簽的“鍵”和“值”。
$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);
嘗試這個:
$result = $ec2->createTags(array(
'Resources' => array($instanceid),
'Tags' => array(
'Tag' => array(
'Key' => '<key>',
'Value' => '<value>'
)
)
));
您需要在“標簽”數組中有一個“標簽”數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.