Inventory

Last updated: 2023-09-13 11:09:14

Feature Overview

This document provides an overview of APIs and SDK code samples for COS inventory.
API
Operation
Description
Setting an inventory job
Sets an inventory job for a bucket
Querying Inventory Jobs
Queries the inventory jobs of a bucket
Deleting an Inventory Job
Deletes an inventory job from a bucket

Setting an inventory job

Note

This API (PUT Bucket inventory) is used to create an inventory job for a bucket.

Method prototype

put_bucket_inventory(Bucket, Id, InventoryConfiguration={}, **kwargs)

Sample Request

# -*- coding=utf-8
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import sys
import os
import logging

# Under normal circumstances, use the INFO log level. To locate issues, change it to DEBUG, and the SDK will print communication information with the server.
logging.basicConfig(level=logging.INFO, stream=sys.stdout)

# 1. Set user properties, including secret_id, secret_key, region, etc. Appid has been removed from CosConfig, please include Appid in the Bucket parameter. Bucket is composed of BucketName-Appid.
secret_id = os.environ['COS_SECRET_ID'] # User <1>SecretId</1>. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For more information on how to obtain a sub-account key, visit https://cloud.tencent.com/document/product/598/37140.
secret_key = os.environ['COS_SECRET_KEY'] # User <1>SecretKey</1>. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For more information on how to obtain a sub-account key, visit https://cloud.tencent.com/document/product/598/37140.
region = 'ap-beijing' # Replace it with the actual region, which can be viewed in the console at https://console.cloud.tencent.com/cos5/bucket.
For a list of all regions supported by COS, visit https://cloud.tencent.com/document/product/436/6224
token = None # Token is required for temporary keys but not permanent keys. For more information about how to generate and use a temporary key, see https://cloud.tencent.com/document/product/436/14048.
scheme = 'https' # Specify whether to use HTTP or HTTPS protocol to access COS. This is optional and is https by default.

config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
client = CosS3Client(config)

response = client.put_bucket_inventory(
Bucket='examplebucket-1250000000',
Id='string',
InventoryConfiguration={
'Destination': {
'COSBucketDestination': {
'AccountId': '100000000001',
'Bucket': 'qcs::cos:ap-guangzhou::examplebucket-1250000000',
'Format': 'CSV',
'Prefix': 'string',
'Encryption': {
'SSECOS': {}
}
}
},
'IsEnabled': 'true'|'false',
'Filter': {
'Prefix': 'string'
},
'IncludedObjectVersions':'All'|'Current',
'OptionalFields': {
'Field': [
'Size',
'LastModifiedDate',
'ETag',
'StorageClass',
'IsMultipartUploaded',
'ReplicationStatus'
]
},
'Schedule': {
'Frequency': 'Daily'|'Weekly'
}
}
)

Description

Parameter name
ParameterDescription
Local Disk Types
Required
Bucket
Set the inventory job's bucket in the format of BucketName-APPID. For more information, please refer to Naming Conventions.
String
Required
Id
Inventory job name. Valid characters: a-z, A-Z, 0-9, -, _, .
String
Required
Destination
Inventory job delivery destination information
Dict
Required
COSBucketDestination
Destination bucket information for inventory job result delivery
Dict
Required
AccountId
Destination bucket account information
String
Not required
Bucket
Destination bucket name
String
Required
Format
File format of the inventory result. Valid value: CSV
String
Required
Prefix
Delivery path prefix in the destination bucket
String
Not required
Encryption
Encryption information for file delivery to the destination bucket. Valid value: SSECOS
Dict
Not required
IsEnabled
Inventory job status flag. Valid values: true, false
String
Required
Filter
Filter for inventory analysis objects
Dict
Not required
Prefix
Filter prefix for inventory analysis objects
String
Not required
IncludedObjectVersions
Versioning information inclusion status. Valid values: All, Current
String
Required
OptionalFields
Optional inventory fields
Dict
Not required
Field
Field names, including Size, LastModifiedDate, ETag, StorageClass, IsMultipartUploaded, and ReplicationStatus
List
Not required
Schedule
Inventory job execution schedule
Dict
Required
Frequency
Inventory job execution frequency. Valid values: Daily, Weekly
String
Required

Response description

This API returns None.

Error codes

The following describes some common errors that may occur when making requests using this API.
Error Code
Description
Status code
InvalidArgument
Invalid parameter value
HTTP 400 Bad Request
TooManyConfigurations
The number of inventories has reached the upper limit of 1,000
HTTP 400 Bad Request
AccessDenied
Unauthorized access. You may not have access to the bucket
HTTP 403 Forbidden

Querying Inventory Jobs

Note

This API is used to query the inventory jobs of a bucket.

Method prototype

get_bucket_inventory(Bucket, Id, **kwargs)

Sample Request

# -*- coding=utf-8
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import sys
import os
import logging

# Under normal circumstances, use the INFO log level. To locate issues, change it to DEBUG, and the SDK will print communication information with the server.
logging.basicConfig(level=logging.INFO, stream=sys.stdout)

# 1. Set user properties, including secret_id, secret_key, region, etc. Appid has been removed from CosConfig, please include Appid in the Bucket parameter. Bucket is composed of BucketName-Appid.
secret_id = os.environ['COS_SECRET_ID'] # User <1>SecretId</1>. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For more information on how to obtain a sub-account key, visit https://cloud.tencent.com/document/product/598/37140.
secret_key = os.environ['COS_SECRET_KEY'] # User <1>SecretKey</1>. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For more information on how to obtain a sub-account key, visit https://cloud.tencent.com/document/product/598/37140.
region = 'ap-beijing' # Replace it with the actual region, which can be viewed in the console at https://console.cloud.tencent.com/cos5/bucket.
For a list of all regions supported by COS, visit https://cloud.tencent.com/document/product/436/6224
token = None # Token is required for temporary keys but not permanent keys. For more information about how to generate and use a temporary key, see https://cloud.tencent.com/document/product/436/14048.
scheme = 'https' # Specify whether to use HTTP or HTTPS protocol to access COS. This is optional and is https by default.

config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
client = CosS3Client(config)

response = client.get_bucket_inventory(
Bucket='examplebucket-1250000000',
Id='string'
)

Description

Parameter name
ParameterDescription
Local Disk Types
Required
Bucket
Query the bucket for the inventory job, formatted as BucketName-APPID. For more information, refer to Naming Conventions.
String
Required
Id
Inventory job name. Valid characters: a-z, A-Z, 0-9, -, _, .
String
Required

Response description

Inventory job configuration of the bucket in dict type.
{
'Id': 'string',
'Destination': {
'COSBucketDestination': {
'AccountId': '100000000001',
'Bucket': 'qcs::cos:ap-guangzhou::examplebucket-1250000000',
'Format': 'CSV',
'Prefix': 'string',
'Encryption': {
'SSECOS': {}
}
}
},
'IsEnabled': 'true'|'false',
'Filter': {
'Prefix': 'string'
},
'IncludedObjectVersions':'All'|'Current',
'OptionalFields': {
'Field': [
'Size',
'LastModifiedDate',
'ETag',
'StorageClass',
'IsMultipartUploaded',
'ReplicationStatus'
]
},
'Schedule': {
'Frequency': 'Daily'|'Weekly'
}
}
Parameter name
ParameterDescription
Local Disk Types
Id
Inventory job name. Valid characters: a-z, A-Z, 0-9, -, _, .
String
Destination
Inventory job delivery destination information
Dict
COSBucketDestination
Destination bucket information for inventory job result delivery
Dict
AccountId
Destination bucket account information
String
Bucket
Destination bucket name
String
Format
File format of the inventory result. Valid value: CSV
String
Prefix
Delivery path prefix in the destination bucket
String
Encryption
Encryption information for file delivery to the destination bucket. Valid value: SSECOS
Dict
IsEnabled
Inventory job status flag. Valid values: true, false
String
Filter
Filter for inventory analysis objects
Dict
Prefix
Filter prefix for inventory analysis objects
String
IncludedObjectVersions
Versioning information inclusion status. Valid values: All, Current
String
OptionalFields
Optional inventory fields
Dict
Field
Field names, including Size, LastModifiedDate, ETag, StorageClass, IsMultipartUploaded, and ReplicationStatus
List
Schedule
Inventory job execution schedule
Dict
Frequency
Inventory job execution frequency. Valid values: Daily, Weekly
String

Deleting an Inventory Job

Note

This API is used to delete an inventory job from a bucket.

Method prototype

delete_bucket_inventory(Bucket, Id, **kwargs)

Sample Request

# -*- coding=utf-8
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import sys
import os
import logging

# Under normal circumstances, use the INFO log level. To locate issues, change it to DEBUG, and the SDK will print communication information with the server.
logging.basicConfig(level=logging.INFO, stream=sys.stdout)

# 1. Set user properties, including secret_id, secret_key, region, etc. Appid has been removed from CosConfig, please include Appid in the Bucket parameter. Bucket is composed of BucketName-Appid.
secret_id = os.environ['COS_SECRET_ID'] # User <1>SecretId</1>. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For more information on how to obtain a sub-account key, visit https://cloud.tencent.com/document/product/598/37140.
secret_key = os.environ['COS_SECRET_KEY'] # User <1>SecretKey</1>. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For more information on how to obtain a sub-account key, visit https://cloud.tencent.com/document/product/598/37140.
region = 'ap-beijing' # Replace it with the actual region, which can be viewed in the console at https://console.cloud.tencent.com/cos5/bucket.
For a list of all regions supported by COS, visit https://cloud.tencent.com/document/product/436/6224
token = None # Token is required for temporary keys but not permanent keys. For more information about how to generate and use a temporary key, see https://cloud.tencent.com/document/product/436/14048.
scheme = 'https' # Specify whether to use HTTP or HTTPS protocol to access COS. This is optional and is https by default.

config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
client = CosS3Client(config)

response = client.delete_bucket_inventory(
Bucket='examplebucket-1250000000',
Id='string'
)

Description

Parameter name
ParameterDescription
Local Disk Types
Required
Bucket
The bucket of the deleted inventory job, formatted as BucketName-APPID. For more information, please refer to Naming Convention.
String
Required
Id
Inventory job name. Valid characters: a-z, A-Z, 0-9, -, _, .
String
Required

Response description

This API returns None.