All Products
Search
Document Center

Object Storage Service:bucket-tagging

Last Updated:Apr 03, 2024

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.

Usage notes

  • To add or modify bucket tags, you must have the oss:PutBucketTagging permission. To query bucket tags, you must have the oss:GetBucketTagging permission. To delete bucket tags, you must have the oss:DeleteBucketTagging permission. For more information, see Attach a custom policy to a RAM user.

  • This topic provides sample command lines that work on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil command reference.

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

Bucket tagging 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 in the preceding syntax.

    Parameter

    Description

    bucketname

    The name of the bucket to which you want to add a tag or whose tag you want to modify.

    key#value

    The key-value pair of the tag.

    • The key and value of the tag are separated by a number sign (#) and must be encoded in UTF-8.

    • The key can be up to 64 characters in length and cannot contain the http://, https://, or Aliyun. prefix. The key cannot be left empty.

    • The value can be up to 128 characters in length. The value can be left empty.

    If the tag specified in the command does not exist, the specified tag is added to the bucket. If the tag specified in the command already exists, the existing tag is overwritten.

  • Examples

    The following sample command adds 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

    The following sample output indicates that the tags are added.

    0.300600(s) elapsed

Query bucket tags

  • Command syntax

    ./ossutil64 bucket-tagging --method get oss://bucketname
  • Examples

    The following sample command queries the tags of a bucket named examplebucket:

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

    The following sample output indicates that the examplebucket bucket has two tags: One has a key of tag1 and a value of test1 and the other has a key of tag2 and a value of test2:

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

Delete bucket tags

  • Command syntax

    ./ossutil64 bucket-tagging --method delete oss://bucketname 
  • Examples

    The following sample command deletes 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. To delete specific tags of a bucket, call the DeleteBucketTags operation.

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

    The following sample output indicates that all tags of the examplebucket have been 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, 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 use for the sync command, see Common options.