All Products
Search
Document Center

Object Storage Service:bucket-tagging

Last Updated:Aug 19, 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.

  • For ossutil 1.6.16 and later, you can directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the operating system. For ossutil earlier than 1.6.16, you need to update the binary name based on the operating system. For more information, see ossutil command reference.

  • For more information about bucket tags, see Manage bucket tags.

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

    ossutil bucket-tagging --method put oss://bucketname key#value

    The following table describes the preceding parameters.

    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.

    ossutil 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

    ossutil bucket-tagging --method get oss://bucketname
  • Examples

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

    ossutil 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

    ossutil 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.

    ossutil 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 specify the endpoint of the region in which the bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, add the -i option to specify the AccessKey ID of the specified account, and add the -k option 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:

ossutil bucket-tagging--method put oss://examplebucket key#value -e oss-cn-hangzhou.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about common options, see Common options.