You can call the PutBucketInventory API to configure inventory rules for a bucket.
Notes
An inventory provides information about objects in a bucket, such as their quantity, size, storage class, and encryption status. Note the following when you configure inventory rules:
Before you configure an inventory for a bucket, you must create a RAM role. The RAM role must have permissions to read all objects from the source bucket and write objects to the destination bucket. If you are using the bucket inventory feature for the first time, we recommend that you configure an inventory in the OSS console. After you configure the inventory, you can obtain a RAM role that has the permissions to perform all operations on OSS resources. For more information about the permissions required for the RAM role when you configure an inventory rule, see Bucket inventory.
A bucket supports a maximum of 1,000 inventory rules.
The source bucket for the inventory and the destination bucket for the exported inventory files must be in the same region.
To use the incremental inventory feature, contact technical support to apply. This feature is currently available only in the Mexico (Mexico City) region.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket policies.
API | Action | Description |
PutBucketInventory | oss:PutBucketInventory | Configures inventories for a bucket. |
Request syntax
The `inventoryId` parameter in the request header is required. Its value must match the `Id` request parameter.
Only the China (Qingdao), China (Hohhot), and Germany (Frankfurt) regions support the LastModifyBeginTimeStamp, LastModifyEndTimeStamp, LowerSizeBound, UpperSizeBound, and StorageClass options.
PUT /?inventory&inventoryId=report1 HTTP/1.1
Host: BucketName.oss-cn-hangzhou.aliyuncs.com
Date: Mon, 31 Oct 2016 12:00:00 GMT
Authorization: authorization string
Content-Length: length
<?xml version="1.0" encoding="UTF-8"?>
<InventoryConfiguration>
<Id>report1</Id>
<IsEnabled>true</IsEnabled>
<Destination>
<OSSBucketDestination>
<Format>CSV</Format>
<AccountId>1000000000000000</AccountId>
<RoleArn>acs:ram::1000000000000000:role/AliyunOSSRole</RoleArn>
<Bucket>acs:oss:::destination-bucket</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>TransistionTime</Field>
<Field>ETag</Field>
<Field>StorageClass</Field>
<Field>IsMultipartUploaded</Field>
<Field>EncryptionStatus</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>Request elements
Name | Type | Required | Example | Description |
Id | string | Yes | report1 | The custom inventory name. It must meet the following requirements:
|
IsEnabled | Boolean | Yes | true | Indicates whether the inventory feature is enabled. Valid values:
|
Filter | container | No | N/A | The prefix for filtering objects in the inventory. After you specify a prefix, the inventory filters objects that match the prefix. |
Prefix | string | No | Pics/ | The prefix for filtering rules. Parent node: Filter |
LastModifyBeginTimeStamp | string | No | 1637883649 | The start UNIX timestamp of the last modified time for filtered files, in seconds. Valid range: [1262275200, 253402271999] |
LastModifyEndTimeStamp | string | No | 1638347592 | The end UNIX timestamp of the last modified time for filtered files, in seconds. Valid range: [1262275200, 253402271999] |
LowerSizeBound | string | No | 1024 | The minimum size of filtered files, in bytes. Valid range: 0 B to 48.8 TB. |
UpperSizeBound | string | No | 1048576 | The maximum size of filtered files, in bytes. Valid range: greater than 0 B and up to 48.8 TB. |
StorageClass | string | No | Standard,IA | The storage class of filtered files. You can specify multiple storage classes. Valid values:
|
Destination | container | Yes | N/A | Stores the checklist results. |
OSSBucketDestination | container | Yes | N/A | Information about the bucket where exported inventory results are stored. Parent node: Destination |
Format | string | Yes | CSV | The file format of the inventory file. Exported inventory files are CSV files compressed with GZIP. Valid value: CSV Parent node: OSSBucketDestination |
AccountId | string | Yes | 100000000000000 | The AccountId granted by the bucket owner. Parent node: OSSBucketDestination |
RoleArn | string | Yes | acs:ram::100000000000000:role/AliyunOSSRole | The name of the role with permissions to read all files from the source bucket and write files to the destination bucket. Format: Parent node: OSSBucketDestination |
Bucket | string | Yes | acs:oss:::bucket_0001 | The bucket where exported inventory files are stored. Parent node: OSSBucketDestination |
Prefix | string | No | prefix1/ | The prefix of the storage path for inventory files. Parent node: OSSBucketDestination |
Encryption | container | No | N/A | The encryption method for inventory files. Valid values:
Parent node: OSSBucketDestination For more information, see Server-side encryption. |
SSE-OSS | container | No | N/A | The container for the SSE-OSS encryption method. Parent node: Encryption |
SSE-KMS | container | No | N/A | The container for the SSE-KMS encryption key. Parent node: Encryption |
KeyId | string | No | keyId | The KMS key ID. Parent node: SSE-KMS |
Schedule | container | Yes | N/A | The container for inventory export frequency information. |
Frequency | string | Yes | Daily | The frequency of inventory file exports. Valid values:
Parent node: Schedule |
IncludedObjectVersions | string | Yes | All | Specifies whether to include object version information in the inventory. Valid values:
|
OptionalFields | container | No | N/A | Configure the items included in the inventory results. |
Field | string | No | Size | The configuration items included in the inventory results.
|
IncrementalInventory | container | No | N/A | The configuration container for incremental inventories. |
IsEnabled | Boolean | Yes | true | Specifies whether to enable incremental inventories. Valid values:
If set to `true`, incremental inventories are enabled, even if `InventoryConfiguration/IsEnabled` is `false`. Parent node: IncrementalInventory |
Schedule | container | Yes | N/A | The container for incremental inventory export frequency information. Parent node: IncrementalInventory |
Frequency | Positive integer | Yes | 600 | The export frequency for incremental inventories, in seconds. The system currently uses a fixed period of 600 seconds. For each period, it automatically creates a directory prefix and generates a manifest file and multiple CSV files for that period. Custom frequency settings are not supported. Parent node: Schedule |
OptionalFields | container | No | N/A | The configuration container for incremental inventory file properties. Parent node: IncrementalInventory |
Field | string | No | Size | The configuration items included in the incremental inventory. Parent node: OptionalFields
|
Response Element
This operation returns only common response headers, such as Content-Length and Date. For more information, see Common response headers.
Examples
Configure inventory rules
Sample request
PUT /?inventory&inventoryId=report1 HTTP/1.1 Host: oss-example.oss-cn-hangzhou.aliyuncs.com Date: Mon, 31 Oct 2016 12:00:00 GMT Authorization: authorization string Content-Length: length <?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>TransistionTime</Field> <Field>ETag</Field> <Field>StorageClass</Field> <Field>IsMultipartUploaded</Field> <Field>EncryptionStatus</Field> </OptionalFields> </InventoryConfiguration>Sample response
HTTP/1.1 200 OK x-oss-request-id: 56594298207FB3044385**** Date: Mon, 31 Oct 2016 12:00:00 GMT Content-Length: 0 Server: AliyunOSS
Configure incremental inventory rules
Sample request
PUT /?inventory&inventoryId=report1 HTTP/1.1 Host: oss-example.oss-cn-hangzhou.aliyuncs.com Date: Mon, 31 Oct 2016 12:00:00 GMT Authorization: authorization string Content-Length: length <?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 response
HTTP/1.1 200 OK x-oss-request-id: 56594298207FB3044385**** Date: Mon, 31 Oct 2016 12:00:00 GMT Content-Length: 0 Server: AliyunOSS
SDKs
This API is available in the following SDKs:
ossutil
For more information about the ossutil command for this operation, see put-bucket-inventory.
Error codes
Error code | HTTP status code | Description |
InvalidArgument | 400 | Invalid parameters are passed. |
InventoryExceedLimit | 400 | The number of inventory configuration rules exceeds the limit. |
AccessDenied | 403 |
|
InventoryAlreadyExist | 409 | The requested inventory rule already exists. |