Configuring Tags for a Bucket
Functions
This operation adds tags to a bucket.
After tags are added to a bucket, all service detail records (SDRs) generated by the requests for this bucket will have the same tags. You can categorize the SDRs for detailed cost analysis. For example, if a running application uploads data to a bucket, you can tag the bucket with the application name. In this manner, the costs on the application can be analyzed using tags in SDRs.
To perform this operation, you must have the PutBucketTagging permission. By default, only the bucket owner can delete the tags of a bucket. The bucket owner can allow other users to perform this operation by setting a bucket policy or granting them the permission.
Restrictions
- A bucket can have up to 10 tags.
Request Syntax
PUT /?tagging HTTP/1.1Host: bucketname.obs.region.example.comDate: dateAuthorization: authorization stringContent-MD5: md5<Tagging><TagSet><Tag><Key>Tag Name</Key><Value>Tag Value</Value></Tag></TagSet></Tagging>
Request Parameters
This request contains no message parameters.
Request Headers
Table 1 lists the request header.
Header | Description | Mandatory |
---|---|---|
Content-MD5 | Explanation: Base64-encoded 128-bit MD5 digest of the message according to RFC 1864. Type: string Example: n58IG6hfM7vqI4K0vnWpog== Restrictions: None Value range: None Default value: None | Yes |
Request Elements
In this request, you must configure bucket tags in the request body. The tag configuration is uploaded in XML format. Table 2 describes the configuration elements.
Header | Description | Mandatory |
---|---|---|
Tagging | Explanation: Root element for TagSet and Tag Type: container Parent: none | Yes |
TagSet | Explanation: Element of the tag set Type: container Parent: Tagging | Yes |
Tag | Explanation: Information element of Tag Type: container Parent: TagSet | Yes |
Key | Explanation: Name of a tag. Type: string. Parent: Tag. Restrictions:
Value range: A string between 0 and 36 characters long. Default value: None | Yes |
Value | Explanation: Tag value. Type: string. Parent: Tag. Restrictions:
Value range: A string of 0 (included) to 43255 (excluded) characters. Default value: None | Yes |
Response Syntax
HTTP/1.1 status_codex-obs-request-id: request idx-obs-id-2: idContent-Length: lengthDate: date
Response Headers
The response to the request uses common headers. For details, see Table 1.
Response Elements
This response contains no elements.
Error Responses
In addition to common error codes, this API also returns other error codes. The following table lists common errors and possible causes. For details, see Table 3.
Error Code | Description | HTTP Status Code |
---|---|---|
InvalidTagError | An invalid tag is provided when configuring bucket tags. | 400 Bad Request |
MalformedXMLError | An incorrect XML format is provided when configuring bucket tags. | 400 Bad Request |
Sample Request
This example adds a tag whose key is TagKey(Name1) and value is TagValue(Value1) to bucket examplebucket.
PUT /?tagging HTTP/1.1User-Agent: curl/7.29.0Host: examplebucket.obs.region.example.comAccept: */*Date: Wed, 27 Jun 2018 13:22:50 GMTAuthorization: OBS H4IPJX0TQTHTHEBQQCEC:Pf1ZyGvVYg2BzOjokZ/BAeR1mEQ=Content-MD5: MnAEvkfQIGnBpchOE2U6Og==Content-Length: 182<Tagging xmlns="http://obs.example.com/doc/2015-06-30/"><TagSet><Tag><Key>TagKey%28Name1%29</Key><Value>TagValue%28Value1%29</Value></Tag></TagSet></Tagging>
Sample Response
HTTP/1.1 204 No ContentServer: OBSx-obs-request-id: BF26000001643FEBA09B1ED46932CD07x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSEZp87iEirC6DggPB5cN49pSvHBWClgDate: Wed, 27 Jun 2018 13:22:50 GMT
- Functions
- Restrictions
- Request Syntax
- Request Parameters
- Request Headers
- Request Elements
- Response Syntax
- Response Headers
- Response Elements
- Error Responses
- Sample Request
- Sample Response