All Products
Search
Document Center

Object Storage Service:put-bucket-inventory

Last Updated:Aug 30, 2024

Configures an inventory for a bucket.

Usage notes

  • Only the bucket owner and RAM users that have the oss:PutBucketInventory permission can configure inventories for the bucket.

  • 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.

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

The container that stores the configuration information of the inventory.

--inventory-id

string

The ID of the inventory.

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>
    </InventoryConfiguration>
  • JSON format:

    [
      {
        "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",
            ...
          ]
        },
        "Id": "string"
      },
      ...
    ]
Note

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

Examples

Configure an inventory 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\"]}}"