All Products
Search
Document Center

Object Storage Service:put-bucket-inventory

Last Updated:Feb 07, 2026

Configures an inventory for a bucket.

Usage notes

  • Only the bucket owner or a Resource Access Management (RAM) user with the oss:PutBucketInventory permission can configure inventory rules.

  • Before you configure an inventory, make sure that you have a RAM role that is authorized to access all objects in the bucket for which you want to configure the inventory and write data to the bucket in which you want to store inventory lists. If you use the bucket inventory feature for the first time, we recommend that you configure an inventory in the Object Storage Service (OSS) console. After you configure the inventory, you can obtain the RAM role that has the permissions to perform all operations on OSS resources. For more information about the permissions of the RAM role that is required to configure inventories, see Bucket inventory.

  • You can configure up to 1,000 inventories for a bucket.

  • The bucket in which you want to store inventory lists must be in the same region as the bucket for which you want to configure an inventory.

  • To use the incremental inventory feature, contact Technical Support to request access. This feature is currently available only in the Mexico region.

Command syntax

ossutil api put-bucket-inventory --bucket value --inventory-id value --inventory-configuration value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--inventory-configuration

string

Configuration information for the storage checklist.

--inventory-id

string

The ID of the checklist task.

Note

The put-bucket-inventory command is the equivalent of the PutBucketInventory command. For more information about the API operation, see PutBucketInventory.

--inventory-configuration

The --inventory-configuration parameter supports XML and JSON formats. If the value of the parameter starts with "file://", the configurations are loaded from the specified file.

  • XML format:

    <InventoryConfiguration>
      <Id>string</Id>
      <IsEnabled>boolean</IsEnabled>
      <Destination>
        <OSSBucketDestination>
          <Bucket>string</Bucket>
          <Prefix>string</Prefix>
          <Encryption>
            <SSE-OSS>
            </SSE-OSS>
            <SSE-KMS>
              <KeyId>string</KeyId>
            </SSE-KMS>
          </Encryption>
          <Format>string</Format>
          <AccountId>string</AccountId>
          <RoleArn>string</RoleArn>
        </OSSBucketDestination>
      </Destination>
      <Schedule>
        <Frequency>string</Frequency>
      </Schedule>
      <Filter>
        <Prefix>string</Prefix>
      </Filter>
      <IncludedObjectVersions>string</IncludedObjectVersions>
      <OptionalFields>
        <Field>string</Field>
        ...
      </OptionalFields>
      <IncrementalInventory>
          <IsEnabled>boolean</IsEnabled>
          <Schedule>
            <Frequency>integer</Frequency>
          </Schedule>
          <OptionalFields>
            <Field>string</Field>
             ...
          </OptionalFields>
        </IncrementalInventory>
    </InventoryConfiguration>
  • JSON format:

    [
      {
        "Id": "string",
        "IsEnabled": boolean,
        "Destination": {
          "OSSBucketDestination": {
            "Format": "string",
            "AccountId": "string",
            "RoleArn": "string",
            "Bucket": "string",
            "Prefix": "string",
            "Encryption": {
              "SSE-OSS": {
              
              },
              "SSE-KMS": {
                "KeyId": "string"
              }
            }
          }
        },
        "Schedule": {
          "Frequency": "string"
        },
        "Filter": {
          "Prefix": "string"
        },
        "IncludedObjectVersions": "string",
        "OptionalFields": {
          "Field": [
            "string",
            ...
          ]
        },
        "IncrementalInventory": {
          "IsEnabled": "boolean",
          "Schedule": {
            "Frequency": "integer"
          },
          "OptionalFields": {
            "Field": [
              "string",
              ...
            ]
          }
         }
    ]
Note

For more information about supported global command-line options, see Command-line options.

Examples

Configure an inventory rule

The following examples show how to configure an inventory rule named report1 for a bucket named examplebucket.

  • Use an XML configuration file (inventory-configuration.xml in this example)

    <?xml version="1.0" encoding="UTF-8"?>
    <InventoryConfiguration>
      <Id>report1</Id>
        <IsEnabled>true</IsEnabled>
      <Filter>
        <Prefix>Pics/</Prefix>
        <LastModifyBeginTimeStamp>1637883649</LastModifyBeginTimeStamp>
        <LastModifyEndTimeStamp>1638347592</LastModifyEndTimeStamp>
        <LowerSizeBound>1024</LowerSizeBound>
        <UpperSizeBound>1048576</UpperSizeBound>
        <StorageClass>Standard,IA</StorageClass>
      </Filter>
      <Destination>
        <OSSBucketDestination>
          <Format>CSV</Format>
          <AccountId>100000000000000</AccountId>
          <RoleArn>acs:ram::100000000000000:role/AliyunOSSRole</RoleArn>
          <Bucket>acs:oss:::destbucket</Bucket>
          <Prefix>prefix1/</Prefix>
          <Encryption>
            <SSE-KMS>
              <KeyId>keyId</KeyId>
            </SSE-KMS>
          </Encryption>
        </OSSBucketDestination>
      </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>EncryptionStatus</Field>
      </OptionalFields>
    </InventoryConfiguration>

    Sample command:

    ossutil api put-bucket-inventory --bucket examplebucket --inventory-id report1 --inventory-configuration file://inventory-configuration.xml
  • Use a JSON configuration file (inventory-configuration.json in this example)

    {
      "Id": "report1",
      "IsEnabled": "true",
      "Filter": {
        "Prefix": "Pics/",
        "LastModifyBeginTimeStamp": "1637883649",
        "LastModifyEndTimeStamp": "1638347592",
        "LowerSizeBound": "1024",
        "UpperSizeBound": "1048576",
        "StorageClass": "Standard,IA"
      },
      "Destination": {
        "OSSBucketDestination": {
          "Format": "CSV",
          "AccountId": "100000000000000",
          "RoleArn": "acs:ram::100000000000000:role/AliyunOSSRole",
          "Bucket": "acs:oss:::destbucket",
          "Prefix": "prefix1/",
          "Encryption": {
            "SSE-KMS": {
              "KeyId": "keyId"
        	 }
          }
        }
      },
      "Schedule": {
        "Frequency": "Daily"
      },
      "IncludedObjectVersions": "All",
      "OptionalFields": {
        "Field": [
          "Size",
          "LastModifiedDate",
          "ETag",
          "StorageClass",
          "IsMultipartUploaded",
          "EncryptionStatus"
          ]
        }
    }

    Sample command:

    ossutil api put-bucket-inventory --bucket examplebucket --inventory-id report1 --inventory-configuration file://inventory-configuration.json
  • Use JSON parameters in the command line

    ossutil api put-bucket-inventory --bucket examplebucket --inventory-id report1 --inventory-configuration "{\"Id\":\"report1\",\"IsEnabled\":\"true\",\"Filter\":{\"Prefix\":\"Pics/\",\"LastModifyBeginTimeStamp\":\"1637883649\",\"LastModifyEndTimeStamp\":\"1638347592\",\"LowerSizeBound\":\"1024\",\"UpperSizeBound\":\"1048576\",\"StorageClass\":\"Standard,IA\"},\"Destination\":{\"OSSBucketDestination\":{\"Format\":\"CSV\",\"AccountId\":\"100000000000000\",\"RoleArn\":\"acs:ram::100000000000000:role/AliyunOSSRole\",\"Bucket\":\"acs:oss:::destbucket\",\"Prefix\":\"prefix1/\",\"Encryption\":{\"SSE-KMS\":{\"KeyId\":\"keyId\"}}}},\"Schedule\":{\"Frequency\":\"Daily\"},\"IncludedObjectVersions\":\"All\",\"OptionalFields\":{\"Field\":[\"Size\",\"LastModifiedDate\",\"ETag\",\"StorageClass\",\"IsMultipartUploaded\",\"EncryptionStatus\"]}}"

Configure an incremental inventory rule

The following example shows how to configure an inventory rule named report1 for the examplebucket bucket.

  • Use an XML configuration file. The following code shows the content of inventory-configuration.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <InventoryConfiguration>
        <Id>Report-1</Id>
        <IsEnabled>true</IsEnabled>
        <Filter>
          <Prefix>test</Prefix>
        </Filter>
        <Destination>
          <OSSBucketDestination>
            <Format>CSV</Format>
            <AccountId>12xxxxxx29</AccountId>
            <RoleArn>acs:ram::12xxxxxx29:role/bucket-inventory-role</RoleArn>
            <Bucket>acs:oss:::test-inc-bi-bj</Bucket>
            <Prefix>Report-1</Prefix>
          </OSSBucketDestination>
        </Destination>
        <Schedule>
          <Frequency>Weekly</Frequency>
        </Schedule>
        <IncludedObjectVersions>All</IncludedObjectVersions>
        <OptionalFields>
          <Field>Size</Field>
          <Field>LastModifiedDate</Field>
          <Field>ETag</Field>
          <Field>StorageClass</Field>
        </OptionalFields>
        <IncrementalInventory>
          <IsEnabled>true</IsEnabled>
          <Schedule>
            <Frequency>600</Frequency>
          </Schedule>
          <OptionalFields>
            <Field>SequenceNumber</Field>
            <Field>RecordType</Field>
            <Field>RecordTimestamp</Field>
            <Field>Requester</Field>
            <Field>RequestId</Field>
            <Field>SourceIp</Field>
            <Field>Size</Field>
            <Field>StorageClass</Field>
            <Field>LastModifiedDate</Field>
            <Field>ETag</Field>
            <Field>IsMultipartUploaded</Field>
            <Field>ObjectType</Field>
            <Field>ObjectAcl</Field>
            <Field>Crc64</Field>
            <Field>EncryptionStatus</Field>
          </OptionalFields>
        </IncrementalInventory>
      </InventoryConfiguration>

    Sample command:

    ossutil api put-bucket-inventory --bucket examplebucket --inventory-id report1 --inventory-configuration file://inventory-configuration.xml