create_tags ( $resource_id, $tag, $opt )

Adds or overwrites tags for the specified resources. Each resource can have a maximum of 10 tags. Each tag consists of a key-value pair. Tag keys must be unique per resource.

Access

public

Parameters

Parameter

Type

Required

Description

$resource_id

string
array

Required

One or more IDs of resources to tag. This could be the ID of an AMI, an instance, an EBS volume, or snapshot, etc. Pass a string for a single value, or an indexed array for multiple values.

$tag

array

Required

The tags to add or overwrite for the specified resources. Each tag item consists of a key-value pair.

  • x - array - Optional - This represents a simple array index.
    • Key - string - Optional - The tag’s key.
    • Value - string - Optional - The tag’s value.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Create new tags for a given resource ID.

$ec2 = new AmazonEC2();

$response = $ec2->create_tags('aki-00006369', array(
	array('Key' => 'alpha', 'Value' => 'abc'),
	array('Key' => 'alpha', 'Value' => 'def'),
	array('Key' => 'beta', 'Value' => 'ghi'),
));

var_dump($response->isOK());
Result:
bool(true)

Related Methods

Source

Method defined in services/ec2.class.php | Toggle source view (16 lines) | View on GitHub

public function create_tags($resource_id, $tag, $opt = null)
{
    if (!$opt) $opt = array();
            
    // Required list (non-map)
    $opt = array_merge($opt, CFComplexType::map(array(
        'ResourceId' => (is_array($resource_id) ? $resource_id : array($resource_id))
    )));
    
    // Required list + map
    $opt = array_merge($opt, CFComplexType::map(array(
        'Tag' => (is_array($tag) ? $tag : array($tag))
    )));

    return $this->authenticate('CreateTags', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback