Amazon AWS,使用PHP SDK 2为ec2实例创建名称标签

I'm using the latest version (2) of SDK for php. Below is a snippet of code for assigning a name tag to existing instance:

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

Output:

Failed to create tag name: exception 'Guzzle\Service\Exception\ValidationException' with message 'Validation errors: [Tags][Name][Tag] must be of type object' in /Users/harry/Documents/workspace/BigData/vendor/guzzle/guzzle/src/Guzzle/Service/Command/AbstractCommand.php:394 Stack trace: #0

I'm guessing something is wrong with the way I pass the argument, but just couldn't figure out the correct way of doing this

The API link for createTags method is here: http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ec2.Ec2Client.html#_createTags

Try this:

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

You need to have an array of 'Tag' inside the 'Tags' array.

You have to specify the 'Key' and 'Value' of each tag.

$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);