Bucket Lifecycle Management
Updated at:2025-11-03
Application scenarios
Data has a lifecycle, spanning from creation to archiving and eventually deletion, which forms a complete cycle. Data is frequently accessed and read in its early stages, cools down and gets archived over time, and is ultimately deleted. Lifecycle management in object storage services helps users automate the management of data lifecycle. It is generally useful for the following situations:
- Automatically archive or delete data when it reaches a specified age.
- Perform specific operations at predefined times.
Create a new lifecycle configuration
- Basic workflow
- Create a BosClient instance.
- Call the putBucketLifecycle() method
- Example code
JavaScript
1const rules = {
2 id: 'rules1',
3 status: 'enabled',
4 action: {
5 name: 'Transition',
6 storageClass: 'STANDARD_IA',
7 resource: ['baidubosmty2/*'],
8 condition: {
9 time: {
10 dateGreaterThan: 'XXXX-XX-XXTXX:XX:XXZ'
11 }
12 }
13 }
14}
15client.putBucketLifecycle(<bucketName>,<rules>)
16 .then(function(response){
17 // Operation
18})
19.catch(err){}
Note:
- Only the bucket owner with full permissions can carry out this operation.
- "resource" indicates resources to which the rules apply. Example: To apply to objects in samplebucket with the
prefix/:samplebucket/prefix/*; to apply to all objects in samplebucket:samplebucket/*. For detailed explanations of parameters related to the lifecycle management function and configuration precautions, please refer to [PutBucketLifecycle API](BOS/API Reference/Bucket-Related Interface/Lifecycle/PutBucketLifecycle.md).
Read the lifecycle configuration of the bucket
- Basic workflow
- Create a BosClient instance.
- Call the getBucketLifecycle() method
- Example code
JavaScript
1client.getBucketLifecycle(<bucketName>)
2 .then(function(response){
3 if (resnpose) {
4 console.log('lifecycle rules', response)
5 }
6
7})
8.catch(err){}
Delete bucket lifecycle
- Basic workflow
- Create a BosClient instance.
- Call the deleteBucketLifecycle() method
- Example code
JavaScript
1client.deleteBucketLifecycle(<bucketName>)
2 .then(function(response){
3 // Operation
4})
5.catch(err){}
