Apply a set of tags to the specified bucket. Bucket Tags simplify the task of associating Amazon S3 costs with specific buckets.
This operation requires permission to perform s3:PutBucketTagging actions. By default,
the bucket owner is permitted to perform these actions, and can grant permission to other users.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Required |
The name of the bucket to use. |
|
|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
|---|---|
|
A |
Examples
Create, get and delete bucket tags.
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);
#--------------------------------------------------------------------#
# Create a new bucket
$response = $s3->create_bucket($bucket, AmazonS3::REGION_US_STANDARD);
if ($response->isOK())
{
// Give the bucket a moment to create
while (!$s3->if_bucket_exists($bucket))
{
sleep(1);
}
}
#--------------------------------------------------------------------#
# Create new bucket tags
$response = $s3->create_bucket_tags($bucket, array(
'tags' => array(
'project' => 'foo',
'user' => 'bar',
)
));
if ($response->isOK())
{
// Give the configuration a moment to settle in
while (!$s3->get_bucket_tags($bucket)->isOK())
{
sleep(1);
}
}
#--------------------------------------------------------------------#
# Retrieve the bucket tags
$response = $s3->get_bucket_tags($bucket);
print_r($response->body);
echo PHP_EOL;
#--------------------------------------------------------------------#
# Delete the bucket tags
$response = $s3->delete_bucket_tags($bucket);
if ($response->isOK())
{
// Delete the bucket
$response = $s3->delete_bucket($bucket, true);
if ($response->isOK())
{
echo 'Bucket was deleted!' . PHP_EOL;
}
else
{
echo 'Bucket deletion failed. #sadtromboneissad' . PHP_EOL;
}
}
Source
Method defined in services/s3.class.php | Toggle source view (22 lines) | View on GitHub

