Feature Overview
This document provides an overview of APIs and SDK code samples related to lifecycles.
API | Operation | Description |
Setting a Lifecycle Configuration | Sets lifecycle management configuration for a bucket | |
Querying lifecycle | Queries the lifecycle management configuration of a bucket | |
Deleting lifecycle | Deletes the lifecycle management configuration of a bucket |
Setting a Lifecycle Configuration
Note
This API (
PUT Bucket lifecycle) is used to set the lifecycle configuration for a bucket.Sample Request
Sample 1. Transition objects to Standard_IA storage class 30 days after upload
cos.putBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */Rules: [{"ID": "1","Status": "Enabled","Filter": {},"Transition": {"Days": "30","StorageClass": "STANDARD_IA"}}],}, function(err, data) {console.log(err || data);});
Sample 2. Transition objects with the specified directory prefix
dir/ to archive storage class 90 days after uploadcos.putBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */Rules: [{"ID": "2","Filter": {"Prefix": "dir/",},"Status": "Enabled","Transition": {"Days": "90","StorageClass": "ARCHIVE"}}],}, function(err, data) {console.log(err || data);});
Example 3: Clean up the delate marker of expired files 180 days after the upload.
cos.putBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */Rules: [{"ID": "3","Status": "Enabled","Filter": {},"Expiration": {"Days": "180"}}],}, function(err, data) {console.log(err || data);});
Sample 4. Delete parts 30 days after upload
cos.putBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */Rules: [{"ID": "4","Status": "Enabled","Filter": {},"AbortIncompleteMultipartUpload": {"DaysAfterInitiation": "30"}}],}, function(err, data) {console.log(err || data);});
Example 5: Deposit the historical version in archive storage 30 days after it is generated.
cos.putBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */Rules: [{"ID": "5","Status": "Enabled","Filter": {},"NoncurrentVersionTransition": {"NoncurrentDays": "30","StorageClass": 'ARCHIVE'}}],}, function(err, data) {console.log(err || data);});
Description
Parameter | ParameterDescription | Local Disk Types | Required |
Bucket | Bucket for which the lifecycle is configured, in the format of BucketName-APPID | String | Required |
Region | String | Required | |
Rules | List of specific lifecycle rules | ObjectArray | Required |
- ID | Unique rule ID | String | Required |
- Status | Rule status; enumerated values: Enabled, Disabled | String | Required |
- Filter | Specifies the filter | Object | Required |
- - Prefix | Object prefix to be matched by the rule | String | Not required |
- Transition | Rule conversion attributes, indicating when the object storage level is converted to Standard_IA or Archive | Object | Not required |
- - Days | Indicates how many days the action corresponding to the rule will be executed after the last modification date of the object. The valid value of this field is a non-negative integer, and a maximum of 3650 days is supported | Number | Required |
- - StorageClass | Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD | String | Not required |
- NoncurrentVersionTransition | Specifies historical version object conversion attributes | ObjectArray | Not required |
- - NoncurrentDays | Indicates the historical version object is converted after the number of effective days determined by this value | Number | Required |
- - StorageClass | Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD | String | Required |
- Expiration | Expiration attributes of the rule | Object | Not required |
- - ExpiredObjectDeleteMarker | Deletes expired delete marker of the object, enumerated values are true and false, cannot coexist with Days | Boolean | Required |
- - Days | Specifies the number of days after the last modification date of the object for the action corresponding to the rule to be deleted, cannot coexist with ExpiredObjectDeleteMarker | Number | Required |
- AbortIncompleteMultipartUpload | Indicates to delete the parts | Object | Not required |
- - DaysAfterInitiation | Parts are deleted after the number of effective days determined by this value, starting from the file upload time and must be a positive integer | Number | Required |
Callback function description
function(err, data) { ... }
Parameter | ParameterDescription | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Object returned when the request is successful. If the request fails, this parameter is empty. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
Querying lifecycle
Note
This API (GET Bucket lifecycle) is used to query the lifecycle management configuration of a bucket.
Sample Request
cos.getBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */}, function(err, data) {console.log(err || data);});
Sample response
{"Rules": [{"ID": "1","Filter": "","Status": "Enabled","Transition": {"Days": "30","StorageClass": "STANDARD_IA"}}, {"ID": "2","Filter": {"Prefix": "dir/"},"Status": "Enabled","Transition": {"Days": "90","StorageClass": "ARCHIVE"}}, {"ID": "3","Filter": "","Status": "Enabled","Expiration": {"Days": "180"}}, {"ID": "4","Filter": "","Status": "Enabled","AbortIncompleteMultipartUpload": {"DaysAfterInitiation": "30"}}, {"ID": "5","Filter": "","Status": "Enabled","NoncurrentVersionTransition:": {"NoncurrentDays": "30","StorageClass": "ARCHIVE"}}],"statusCode": 200,"headers": {}}
Description
Parameter name | Description | Local Disk Types | Required |
Bucket | Bucket for which the lifecycle is queried, in the format of BucketName-APPID | String | Required |
Region | String | Required |
Callback function description
function(err, data) { ... }
Parameter | ParameterDescription | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Object returned when the request is successful. If the request fails, this parameter is empty. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
- Rules | List of specific lifecycle rules | ObjectArray |
- - ID | Unique rule ID | String |
- - Status | Rule status; enumerated values: Enabled, Disabled | String |
- - Filter | Specifies the filter | Object |
- - - Prefix | Object prefix to be matched by the rule | String |
- - Transition | Rule conversion attributes, indicating when the object storage level is converted to Standard_IA or Archive | ObjectArray |
- - - Days | Indicates how many days the action corresponding to the rule will be executed after the last modification date of the object. The valid value of this field is a non-negative integer, and a maximum of 3650 days is supported | Number |
- - - StorageClass | Indicates the storage class of the transitioned object; enumerated values: STANDARD, STANDARD_IA, ARCHIVE | String |
- - NoncurrentVersionTransition | Specifies historical version object conversion attributes | ObjectArray |
- - - NoncurrentDays | Indicates the historical version object is converted after the number of effective days determined by this value | Number |
- - - StorageClass | Indicates the storage class of the object after transition; enumerated values: STANDARD, STANDARD_IA, ARCHIVE. Default value: STANDARD | String |
- - Expiration | Expiration attributes of the rule | Object |
- - - ExpiredObjectDeleteMarker | Deletes expired delete marker of the object, enumerated values are true and false, cannot coexist with Days | Boolean |
- - - Days | Specifies the number of days after the last modification date of the object for the action corresponding to the rule to be deleted, cannot coexist with ExpiredObjectDeleteMarker | Number |
- - AbortIncompleteMultipartUpload | Indicates to delete the parts | Object |
- - - DaysAfterInitiation | Parts are deleted after the number of effective days determined by this value, starting from the file upload time and must be a positive integer | Number |
Deleting lifecycle
Note
This API (GET Bucket lifecycle) is used to query the lifecycle configuration of a bucket.
Sample Request
cos.deleteBucketLifecycle({Bucket: 'examplebucket-1250000000', /* Required */Region: 'COS_REGION', /* The region where the bucket is located, required field */}, function(err, data) {console.log(err || data);});
Description
Parameter | ParameterDescription | Local Disk Types | Required |
Bucket | Bucket for which the lifecycle configuration is deleted, in the format of BucketName-APPID | String | Required |
Region | String | Required |
Callback function description
function(err, data) { ... }
Parameter name | Description | Local Disk Types |
err | Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, see Error Codes. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |
data | Object returned when the request is successful. If the request fails, this parameter is empty. | Object |
- statusCode | HTTP status code, such as 200, 403, and 404 | Number |
- headers | Returned headers | Object |