All Products
Search
Document Center

Object Storage Service:put-bucket-tags

Last Updated:Sep 05, 2024

Adds tags to or modifies the tags of a bucket.

Usage notes

  • By default, an Alibaba Cloud account has the permissions to add tags to or modify the tags of a bucket. To add tags to or modify the tags of a bucket by using a RAM user or Security Token Service (STS), you must have the oss:PutBucketTags permission. For more information, see Attach a custom policy to a RAM user.

  • When you run the put-bucket-tags command to add tags to a bucket, the new tags overwrite the existing tags.

  • You can configure up to 20 tags for a bucket. A tag is a key-value pair.

Command syntax

ossutil api put-bucket-tags --bucket value --tagging value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--tagging

string

The container in which the tags are stored.

Note

The put-bucket-tags command corresponds to the PutBucketTags operation. For more information about the parameters in the PutBucketTags operation, see PutBucketTags.

--tagging

The --tagging option supports both the XML and JSON formats. If the value of the option contains the file:// prefix, ossutil reads configurations from a configuration file.

  • XML format:

    <Tagging>
      <TagSet>
        <Tag>
          <Key>string</Key>
          <Value>string</Value>
        </Tag>
        ...
      </TagSet>
    </Tagging>
  • JSON format:

    {
      "TagSet": {
        "Tag": [
          {
            "Key": "string",
            "Value": "string"
          },
          ...
        ]
      }
    }
Note

For more information about supported global command-line options, see Global command-line options.

Examples

The following examples show how to add tags to or modify the tags of a bucket named examplebucket.

  • Create a configuration file named tagging.xml and add the following code to the configuration file:

    <?xml version="1.0" encoding="UTF-8"?>
    <Tagging>
      <TagSet>
        <Tag>
          <Key>key1</Key>
          <Value>value1</Value>
        </Tag>
        <Tag>
          <Key>key2</Key>
          <Value>value2</Value>
        </Tag>
      </TagSet>
    </Tagging>

Sample command:

ossutil api put-bucket-tags --bucket examplebucket --tagging file://tagging.xml
  • Create a configuration file named tagging.json and add the following code to the configuration file:

    {
        "TagSet": {
            "Tag": [
                {
                    "Key": "key1",
                    "Value": "value1"
                },
                {
                    "Key": "key2",
                    "Value": "value2"
                }
            ]
        }
    }

    Sample command:

    ossutil api put-bucket-tags --bucket examplebucket --tagging file://tagging.json
  • Configure parameters in the following command in the JSON format:

    ossutil api put-bucket-tags --bucket examplebucket --tagging "{\"TagSet\":{\"Tag\":[{\"Key\":\"key1\",\"Value\":\"value1\"},{\"Key\":\"key2\",\"Value\":\"value2\"}]}}"