All Products
Search
Document Center

Object Storage Service:put-bucket-tags

Last Updated:Mar 19, 2026

Adds tags to or replaces the existing tags of a bucket.

Usage notes

  • By default, an Alibaba Cloud account has permission to add or modify bucket tags. RAM users and Security Token Service (STS) principals require the oss:PutBucketTags permission. For more information, see Attach a custom policy to a RAM user.

  • Running put-bucket-tags replaces all existing tags on the bucket.

  • A bucket can have at most 20 tags. Each tag is a key-value pair.

Syntax

ossutil api put-bucket-tags --bucket <value> --tagging <value> [flags]
ParameterTypeDescription
--bucketstringThe name of the bucket.
--taggingstringThe tag configuration, in XML or JSON format. Use the file:// prefix to load from a file.
Note

This command maps to the PutBucketTags API operation. For a full list of supported flags, see Global command-line options.

--tagging format

The --tagging option accepts XML or JSON. Pass the value inline or reference a file using the file:// prefix.

XML:

<Tagging>
  <TagSet>
    <Tag>
      <Key>string</Key>
      <Value>string</Value>
    </Tag>
    ...
  </TagSet>
</Tagging>

JSON:

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

Examples

All three examples tag examplebucket with environment=production and team=billing.

Using an XML file:

Create tagging.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Tagging>
  <TagSet>
    <Tag>
      <Key>environment</Key>
      <Value>production</Value>
    </Tag>
    <Tag>
      <Key>team</Key>
      <Value>billing</Value>
    </Tag>
  </TagSet>
</Tagging>
ossutil api put-bucket-tags --bucket examplebucket --tagging file://tagging.xml

Using a JSON file:

Create tagging.json:

{
  "TagSet": {
    "Tag": [
      {
        "Key": "environment",
        "Value": "production"
      },
      {
        "Key": "team",
        "Value": "billing"
      }
    ]
  }
}
ossutil api put-bucket-tags --bucket examplebucket --tagging file://tagging.json

Inline JSON:

ossutil api put-bucket-tags --bucket examplebucket --tagging "{\"TagSet\":{\"Tag\":[{\"Key\":\"environment\",\"Value\":\"production\"},{\"Key\":\"team\",\"Value\":\"billing\"}]}}"