Configuring Tags for a Bucket
Functions
Tags are used to identify buckets or objects in OBS and help you classify buckets or objects. Tags can be added to a bucket when or after the bucket is created. You can call this API to add tags to an existing 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.
Constraints
- A tag is structured as a key-value pair that is case sensitive.
- A bucket can have up to 20 tags by default. Each tag has only one key and one value.
- Each key must be unique among all tags of a bucket, whereas the tag values can be repetitive or left blank.
- It takes about three minutes for an added tag to take effect.
Authorization Information
To call this API, you must be the bucket owner or have the permission to configure tags for a bucket. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.
- If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
- If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you need to grant the obs:bucket:PutBucketTagging permission. For details, see Creating a Custom IAM Policy.
- If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you need to grant the obs:bucket:putBucketTagging permission, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.
Action
Access Level
Resource Type (*: Required)
Dependencies
obs:bucket:putBucketTagging
Tagging
bucket *
-
-
-
- g:RequestTag/<tag-key>
- g:TagKeys
- obs:EpochTime
- obs:SourceIp
- obs:TlsVersion
- obs:CustomDomain
- If you use bucket policies for authorization, you need to grant the obs:bucket:PutBucketTagging permission. For details, see Creating a Custom Bucket Policy.
Request Syntax
The following is an example request. Replace BucketName with your bucket name and RegionID with the ID of the region where your bucket resides. You can obtain the region ID by referring to Supported Regions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | PUT /?tagging HTTP/1.1 Host: BucketName.obs.RegionID.myhuaweicloud.com Date: GMT Date Authorization: SignatureValue Content-SHA256: SHA256 Content-MD5: md5 <Tagging> <TagSet> <Tag> <Key>Tag Name</Key> <Value>Tag Value</Value> </Tag> </TagSet> </Tagging> |
URI Parameters
This request contains no message parameters.
Request Headers
Table 1 lists the request headers.
| Header | Type | Mandatory | Description |
|---|---|---|---|
| Content-SHA256 | String | Yes | Base64-encoded 256-bit SHA256 digest of the message according to SHA. Example: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI= |
| Content-MD5 | String | Yes | Definition Base64-encoded 128-bit MD5 digest of the message according to RFC 1864. You can also configure the Content-SHA256 header whose value is the Base64-encoded 256-bit SHA-256 digest of the message. Configure either Content-MD5 or Content-SHA256. Example: n58IG6hfM7vqI4K0vnWpog== Constraints None Range None Default Value None |
Request Body
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 | Type | Mandatory | Description |
|---|---|---|---|
| Tagging | XML | Yes | Definition Root element for TagSet and Tag Constraints N/A |
| TagSet | XML | Yes | Definition Parent element of Tag. Parent: Tagging Constraints A maximum of 20 tags can be set for a bucket. That means a TagSet can contain a maximum of 20 Tag nodes. |
| Tag | XML | Yes | Definition Information element of Tag Parent: TagSet Constraints A maximum of 20 tags can be set for a bucket. That means a TagSet can contain a maximum of 20 Tag nodes. |
| Key | String | Yes | Definition Name of a tag. Parent: Tag. Constraints
Range A string between 1 and 128 characters long. Default Value None |
| Value | String | Yes | Definition Tag value. Parent: Tag. Constraints
Range A string of 0 (included) to 255 (excluded) characters. Default Value None |
Response Syntax
1 2 3 4 5 | HTTP/1.1 status_code x-obs-request-id: request id x-obs-id-2: id Content-Length: length Date: date |
Response Headers
This response uses common headers. For details, see Table 1.
Response Body
The response of this API does not contain a response body.
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.
Sample Request
This example adds a tag whose key is TagKey(Name1) and value is TagValue(Value1) to bucket examplebucket.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | PUT /?tagging HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Accept: */* Date: Wed, 27 Jun 2018 13:22:50 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:Pf1ZyGvVYg2BzOjokZ/BAeR1mEQ= Content-SHA256: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI= Content-MD5: MnAEvkfQIGnBpchOE2U6Og== Content-Length: 182 <Tagging xmlns="http://obs.ap-southeast-1.myhuaweicloud.com/doc/2015-06-30/"> <TagSet> <Tag> <Key>TagKey%28Name1%29</Key> <Value>TagValue%28Value1%29</Value> </Tag> </TagSet> </Tagging> |
Sample Response
1 2 3 4 5 | HTTP/1.1 204 No Content Server: OBS x-obs-request-id: BF26000001643FEBA09B1ED46932CD07 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSEZp87iEirC6DggPB5cN49pSvHBWClg Date: Wed, 27 Jun 2018 13:22:50 GMT |
Using SDKs to Call APIs
You are advised to use OBS SDKs to call APIs. SDKs encapsulate APIs to simplify development. You can call SDK API functions to access OBS without manually calculating signatures.
References
- For more information about bucket tags, see Adding Tags to a Bucket.
- For details about the billing items involved in API operations, see Billing Items.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot

