Object Storage Service (OSS) allows you to configure bucket tagging to classify and manage buckets. For example, you can use the bucket tagging feature to list buckets that have specific tags and configure access control lists (ACLs) for buckets that have specific tags. This topic describes how to run the bucket-tagging command to add, modify, query, or delete bucket tags.

Important
  • Sample command lines in this topic are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil.
  • For more information about bucket tagging, see Configure bucket tagging.

Add tags to a bucket or modify the tags of a bucket

The bucket tagging feature uses a key-value pair as a tag to identify buckets. Each bucket can have up to 10 tags. Only the bucket owner and users who are granted the PutBucketTags permission can add tags to the bucket or modify the tags of the bucket. If other users add tags to the bucket or modify the tags of the bucket, 403 Forbidden is returned with the error code AccessDenied.

  • Command syntax
    ./ossutil64 bucket-tagging --method put oss://bucketname key#value

    The following table describes the parameters specified in the preceding statement.

    ParameterDescription
    bucketnameThe name of the bucket to which you want to add a tag or whose tag you want to modify.
    key#valueThe key-value pair that contains the tag information.
    • The key and value of the tag are separated by a number sign (#) and must be encoded in UTF-8.
    • The key of a tag can be up to 64 characters in length and cannot start with http://, https://, or Aliyun. The key of a tag cannot be left empty.
    • The value of a tag can be up to 128 characters in length and can be left empty.

    If a bucket has no tags, you can run this command to add tags to the bucket. If a bucket has tags, you can run this command to overwrite existing tags.

  • Example

    You can run the following command to add two tags to a bucket named examplebucket. One tag has a key of tag1 and a value of test1, and the other tag has a key of tag2 and a value of test2.

    ./ossutil64 bucket-tagging --method put oss://examplebucket  tag1#test1 tag2#test2

    If a similar output is displayed, the tags are added to the bucket:

    0.300600(s) elapsed

Query the tags of a bucket

  • Command syntax
    ./ossutil64 bucket-tagging --method get oss://bucketname
  • Example

    You can run the following command to query the tags of a bucket named examplebucket:

    ./ossutil64 bucket-tagging --method get oss://examplebucket

    If a similar output is displayed, examplebucket is configured with two tags. One tag has the key of tag1 and the value of test1, and the other tag has the key of tag2 and the value of test2.

    index     tag key       tag value
    ---------------------------------------------------
    0         "tag1"        "test1"
    1         "tag2"        "test2"
    
    0.283359(s) elapsed

Delete the tags of a bucket

  • Command syntax
    ./ossutil64 bucket-tagging --method delete oss://bucketname 
  • Example

    You can run the following command to delete all tags of a bucket named examplebucket:

    Note ossutil allows you to delete all tags of a bucket. You cannot use ossutil to delete only specific tags of a bucket. You can call the DeleteBucketTags operation to delete specific tags of a bucket.
    ./ossutil64 bucket-tagging --method delete oss://examplebucket
    If a similar output is displayed, all tags of examplebucket are deleted:
    0.530750(s) elapsed

Common options

If you use ossutil to switch to a bucket that is located in another region, add the -e option to the command to specify the endpoint of the region in which the specified bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, you can add the -i option to the command to specify the AccessKey ID of the specified account, and add the -k option to the command to specify the AccessKey secret of the specified account.

For example, you can run the following command to configure tags for a bucket named examplebucket, which is located in the China (Hangzhou) region and is owned by another Alibaba Cloud account:
./ossutil64 bucket-tagging--method put oss://examplebucket key#value -e oss-cn-hangzhou.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about other common options that you can specify in the sync command, see Common options.