Bucket Inventory Management
Updated at:2025-11-03
Application scenarios
The storage inventory feature helps users manage objects within their buckets. Based on the configured inventory tasks, BOS can scan designated objects daily or weekly and generate an inventory report. This report, stored as a CSV file in a user-defined bucket, lists objects and their corresponding metadata, including attributes specified by the user.
Description:
- This feature is currently fully supported in the North China (Beijing), East China (Suzhou), and South China (Guangzhou) regions.
Set inventory rules
The following code sets an inventory rule:
Plain Text
1# Set the inventory rule name
2inventory_conf_id = "test-inventory-rule-01"
3# Set the source bucket name
4source_bucket_name = "<SOURCE_BUCKET_NAME>"
5# Set the destination bucket for inventory output
6target_bucket_name = "<TARGET_BUCKET_NAME>"
7# Set the directory prefix for inventory output
8target_prefix = "inventory-result/"
9# To disable the inventory, set "status" to "disabled".
10my_inventory = {
11 "id": inventory_conf_id,
12 "status": "enabled",
13 "resource": [source_bucket_name + "/*"],
14 "schedule": "Weekly",
15 "destination":{
16 "targetBucket": target_bucket_name,
17 "targetPrefix": target_prefix,
18 "format": "CSV"
19 }
20}
21# put bucket inventory
22bos_client.put_bucket_inventory(bucket_name, my_inventory)
Note:
- The user must own the source bucket with FULL_CONTROL permissions and also own the target bucket.
- Both the destination and source buckets must exist, belong to the same account, and be in the same region. Cross-account output is not supported.
- BOS allows up to 20 inventory tasks to be created per bucket.
- The inventory list reflects eventual consistency for newly added and overwritten objects as well as for DELETE operations. It is a rolling snapshot of the bucket, which means the content is eventually consistent and may not immediately include objects that were added or deleted recently.
- If an existing rule is already in place, it will be overwritten by the new one.
Obtain the inventory rules of a bucket
The following code can retrieve the configuration of a specified rule for the bucket inventory function:
Plain Text
1# Specify the inventory rule ID
2inventory_conf_id = "test-inventory-rule-01"
3response = bos_client.get_bucket_inventory(bucket_name, inventory_conf_id)
4print(response)
List the inventory rules of a bucket
The following code can list the rules for the bucket inventory function:
Plain Text
1response = bos_client.list_bucket_inventory(bucket_name)
2print(response.inventory_rule_list)
Delete inventory rules
The following code can delete the configuration of a specified rule for the bucket inventory function:
Plain Text
1# Specify the inventory rule ID
2inventory_conf_id = "test-inventory-rule-01"
3response = bos_client.delete_bucket_inventory(bucket_name, inventory_conf_id)
