Configuring Bucket Inventories
Function
The bucket inventory function periodically generates a list of object metadata information for a bucket, helping you better understand object statuses in the bucket. You can call this API to configure bucket inventories. For more information and constraints about bucket inventories, see Bucket Inventories.
Constraints
| Item | Description |
|---|---|
| Bucket version | Inventories can be generated only for OBS 3.0 buckets, but the bucket that stores the inventory files can be any OBS version. |
| Maximum number of bucket inventories | A bucket can have a maximum of 10 inventories. |
| Source and destination buckets |
|
| Functions |
|
| Permissions | OBS must be authorized to upload inventory files to the destination bucket. The destination bucket needs a policy that grants OBS write permissions, with the Principal set to {"Service": "obs"}. |
| Others |
|
Authorization
To call this API, you must be the bucket owner or have the permission to configure inventories 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 must have the obs:bucket:PutBucketInventoryConfiguration 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 must have the obs:bucket:putBucketInventoryConfiguration 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:putBucketInventoryConfiguration
Write
bucket *
-
-
-
- obs:EpochTime
- obs:SourceIp
- obs:TlsVersion
- obs:CustomDomain
- If you use bucket policies for authorization, you must have the obs:bucket:PutBucketInventoryConfiguration permission. For details, see Creating a Custom Bucket Policy.
URI
PUT /
Calling Method
For details, see Calling APIs. Before calling this API, calculate the API signature and add it to the request.
You can debug this API in API Explorer.
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.
PUT /?inventory&id=configuration-id HTTP/1.1 User-Agent: curl/7.29.0 Host: BucketName.obs.RegionID.myhuaweicloud.com Accept: */* Date: GMT Date Authorization: SignatureValue Content-Length: BodyLength Expect: 100-continue <InventoryConfiguration> <Id>configuration-id</Id> <IsEnabled>true</IsEnabled> <Filter> <Prefix>inventoryTestPrefix</Prefix> </Filter> <Destination> <Format>CSV</Format> <Bucket>destbucket</Bucket> <Prefix>dest-prefix</Prefix> </Destination> <Schedule> <Frequency>Daily</Frequency> </Schedule> <IncludedObjectVersions>All</IncludedObjectVersions> <OptionalFields> <Field>Size</Field> <Field>LastModifiedDate</Field> <Field>ETag</Field> <Field>StorageClass</Field> <Field>IsMultipartUploaded</Field> <Field>ReplicationStatus</Field> <Field>EncryptionStatus</Field> </OptionalFields> </InventoryConfiguration>
URI Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| inventory | String | Yes | Definition An identifier that marks this API as related to bucket inventory. Constraints When calculating the signature, add /BucketName/?inventory to CanonicalizedResource. For details, see Using an Authorization Header. Range inventory Default Value N/A |
| id | String | Yes | Definition ID of the inventory configuration, which must be consistent with the inventory configuration ID in the message body. Constraints N/A Range The value can contain a maximum of 64 bytes, including letters (a–z and A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). Default Value N/A |
Request Headers
This request uses common headers. For details, see Table 3.
Request Body
In this request, you must include the bucket inventory configuration in the request body. The inventory configuration is uploaded in an XML file. Table 3 lists the configuration elements.
| Element | Mandatory | Type | Description |
|---|---|---|---|
| InventoryConfiguration | Yes | Container | Definition Inventory configuration. InventoryConfiguration is the parent node of Id, IsEnabled, Filter, Destination, Schedule, IncludedObjectVersions, and OptionalFields. Constraints N/A Range N/A Default Value N/A |
| Id | Yes | String | Definition ID of an inventory configuration, which must be consistent with the inventory configuration ID specified in the request. Parent: InventoryConfiguration Constraints N/A Range The value can contain a maximum of 64 bytes, including letters (a–z and A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). Default Value N/A |
| IsEnabled | Yes | Boolean | Definition Whether the inventory rule is enabled. If this parameter is set to true, inventory files will be generated. If not, inventory files will not be generated. Parent: InventoryConfiguration Constraints N/A Range true: Inventory files will be generated. false: Inventory files will not be generated. Default Value N/A |
| Filter | No | Container | Definition Inventory filter configuration. If configured, inventory files contain only objects that meet the filter criteria (filtering by object name prefix). If no filter criteria are configured, all objects are included. Parent: InventoryConfiguration Constraints N/A Range N/A Default Value N/A |
| Prefix | No | String | Definition Filtering by name prefix. Only objects with the specified name prefix are included in inventory files. Parent: Filter Constraints N/A Range The value can contain a maximum of 1,024 characters. Default Value N/A |
| Schedule | Yes | Container | Definition Time scheduled for generation of inventory files. Parent: InventoryConfiguration Constraints N/A Range N/A Default Value N/A |
| Frequency | Yes | String | Definition Intervals when inventory files are generated. You can set this parameter to Daily or Weekly. An inventory file is generated within one hour after bucket inventory is configured for the first time. Then, inventory files are generated at the specified intervals. Parent: Schedule Constraints N/A Range Daily: Inventory files are generated once a day. Weekly: Inventory files are generated once a week. Default Value N/A |
| Destination | Yes | Container | Definition Destination configuration of an inventory. Parent: InventoryConfiguration Constraints N/A Range N/A Default Value N/A |
| Format | Yes | String | Definition Inventory file format. Only the CSV format is supported. Parent: Destination Constraints N/A Range The value can only be CSV. Default Value N/A |
| Bucket | Yes | String | Definition Name of the bucket for storing inventory files. Parent: Destination Constraints N/A Range N/A Default Value N/A |
| Prefix | No | String | Definition Name prefix for inventory files. If no prefix is configured, the inventory file names will start with the BucketInventory prefix by default. Parent: Destination Constraints N/A Range The value can contain a maximum of 254 characters and cannot contain the following special characters: \*?"<>| Default Value N/A |
| IncludedObjectVersions | Yes | String | Definition Whether the inventory files contain object versioning information. Parent: InventoryConfiguration Constraints N/A Range
Default Value N/A |
| OptionalFields | No | Container | Definition Additional object metadata fields that can be included in inventory files. Parent: InventoryConfiguration Constraints This parameter is used together with Field. Range N/A Default Value N/A |
| Field | No | String | Definition An optional field. An OptionalFields can contain multiple field elements. You can add additional object metadata fields. Parent: OptionalFields Constraints N/A Range Size: object size. LastModifiedDate: time when the object was created. ETag: object ETag. StorageClass: object storage class. IsMultipartUploaded: whether it is a multipart upload object. The value can be true or false. ReplicationStatus: replication status of a CRR object. EncryptionStatus: server-side encryption method. BucketKeyStatus: key status, which can be ENABLED or DISABLED. UserMeta: user-defined metadata. CRC64: CRC64 check on the data content. ObjectType: object type. Default Value N/A |
Response Syntax
1 2 3 4 5 | HTTP/1.1 status_code x-obs-request-id: request id x-obs-id-2: id Date: date Content-Length: length |
Response Headers
This response uses common headers. For details, see Table 1.
Response Body
This response does not contain a response body.
Error Responses
In addition to common error codes, this API also returns some special error codes. Table 4 lists the special error codes and their possible causes.
| Error Code | Description | HTTP Status Code |
|---|---|---|
| MalformedXML | Incorrect XML format of the inventory. | 400 Bad Request |
| InvalidArgument | Invalid parameter. | 400 Bad Request |
| InventoryCountOverLimit | The number of inventories reached the upper limit. | 400 Bad Request |
| PrefixExistInclusionRelationship | The prefix configured for this inventory overlaps with prefixes of existing inventories. | 400 Bad Request |
Sample Request
PUT /?inventory&id=test_id HTTP/1.1
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Accept: */*
Date: Tue, 08 Jan 2019 08:17:10 +0000
Authorization: OBS UDSIAMSTUBTEST000001:/e2fqSfzLDb+0M36D4Op/s5KKr0=
Content-Length: 600
Expect: 100-continue
<InventoryConfiguration>
<Id>test_id</Id>
<IsEnabled>true</IsEnabled>
<Filter>
<Prefix>inventoryTestPrefix</Prefix>
</Filter>
<Destination>
<Format>CSV</Format>
<Bucket>destbucket</Bucket>
<Prefix>dest-prefix</Prefix>
</Destination>
<Schedule>
<Frequency>Daily</Frequency>
</Schedule>
<IncludedObjectVersions>All</IncludedObjectVersions>
<OptionalFields>
<Field>Size</Field>
<Field>LastModifiedDate</Field>
<Field>ETag</Field>
<Field>StorageClass</Field>
<Field>IsMultipartUploaded</Field>
<Field>ReplicationStatus</Field>
<Field>EncryptionStatus</Field>
</OptionalFields>
</InventoryConfiguration> Sample Response
1 2 3 4 5 6 | HTTP/1.1 200 OK Server: OBS x-obs-request-id: 000001682C8545B0680893425D60AB83 x-obs-id-2: 32AAAQAAEAABAAAQAAEAABAAAQAAEAABCSIGTuRtBfo7lpHSt0ZknhdDHmllwd/p Date: Tue, 08 Jan 2019 08:12:38 GMT Content-Length: 0 |
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.
| Python: not supported | C: not supported | Go: not supported | BrowserJS: not supported | .NET: not supported | Android: not supported | iOS: not supported | PHP: not supported | Node.js: not supported |
Helpful Links
- For more information about configuring bucket inventories, see Bucket Inventories.
- 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