Skip to main content

Tag a Bucket

Using this feature you will be able to label boxes. Tags allow you to perform batch operations on boxes with a common tag.

Components

Tag

Each tag consists of a key-value component, which is used as follows:

{
tagList.Add(new Tag() { Key = "Key1", Value = "Value1" }); //REQUIRED
tagList.Add(new Tag() { Key = "Key2", Value = "Value2" }); //REQUIRED
}

Note that by using this function, the new tags will replace the previous tags. If you want to add new tags to the old tags, you must first get the old tags using the GetBucketTaggingAsync request and then pass the set of new and old tags as input to that.

Limits

  • The maximum number of tags for a bucket is 10.
  • The value of the Key for the tags of a bucket must be unique.
  • The value of the Key and the Value for each bucket must be in the form of a string.
  • The length of the Key can be up to 128 Unicode characters and also the length of the Value can be up to 256 Unicode characters.
  • Key and Value are case-sensitive.

Code Sample

using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Reflection;
using System.Collections;

namespace PutBucketTags
{
class PutBucketTags
{
private const string bucketName = "<BUCKET_NAME>";
private static IAmazonS3 _s3Client;
public static void Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("<ACCESS-KEY>", "<SECRET-KEY>");
var config = new AmazonS3Config { ServiceURL = "<ENDPOINT>" };
_s3Client = new AmazonS3Client(awsCredentials, config);
PutBucketTagsAsync().Wait();
}

private static async Task PutBucketTagsAsync()
{
try
{
List<Tag> tagList = new List<Tag>();
// Add parts to the list.
tagList.Add(new Tag() { Key = "Key1", Value = "Value1" });
tagList.Add(new Tag() { Key = "Key2", Value = "Value2" });

PutBucketTaggingResponse response = await _s3Client.PutBucketTaggingAsync(bucketName, tagList);

foreach (PropertyInfo prop in response.GetType().GetProperties())
{
Console.WriteLine($"{prop.Name}: {prop.GetValue(response, null)}");
}

Console.WriteLine($"Tags added to {bucketName} bucket");
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
}