• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Bucket-Related APIs
  5. PUT Bucket lifecycle

PUT Bucket lifecycle

API Description

You can use this API to set lifecycle rules for a bucket, so as to periodically delete objects in the bucket.

Method Definition

ObsClient.setBucketLifecycleConfiguration(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Rules

Array

Mandatory

Lifecycle rules of the bucket

  

Transitions

Array

Optional

List of object transition policies

  

StorageClass

String

Mandatory

Storage class of the object after transition. Possible values are:

  • ObsClient.enums.StorageClassWarm
  • ObsClient.enums.StorageClassCold

Date

String

This parameter is mandatory if Days is not set.

Date when an object will be transited The value must conform with the ISO8601 standards and must be at 00:00 (UTC time), for example, 2018-01-01T00:00:00Z.

Days

Number

This parameter is mandatory if Date is not set.

Number of days after which an object will be transited since its creation. The value must be a positive integer.

  

Expiration

Object

Optional

Expiration time of an object

  

Date

String

This parameter is mandatory if Days is not set.

Date when an object expires. The value must conform with the ISO8601 standards and must be at 00:00 (UTC time), for example, 2018-01-01T00:00:00Z.

Days

Number

This parameter is mandatory if Date is not set.

Number of days after which an object expires since its creation. The parameter value is a positive integer.

ID

String

Optional

Rule ID. The value is a string of no more than 255 characters.

Prefix

String

Mandatory

Object name prefix. It identifies the objects to which the rule applies. The value can be empty, indicating that the rule applies to all objects in the bucket.

Status

String

Mandatory

Whether the current rule is enabled. Possible values are:

  • Enabled
  • Disabled
  

NoncurrentVersionTransitions

Array

Optional

List of noncurrent object version transition policies

  

StorageClass

String

Mandatory

Storage class of the noncurrent object version after transition. Possible values are:

  • ObsClient.enums.StorageClassWarm
  • ObsClient.enums.StorageClassCold

NoncurrentDays

Number

Mandatory

Number of days after which an object will be transited since it becomes a noncurrent version. The parameter value must be a positive integer.

  

NoncurrentVersionExpiration

Object

Optional

Expiration time of a noncurrent object version

  

NoncurrentDays

Number

Mandatory

Number of days after which an object expires since it becomes a noncurrent version. The parameter value must be a positive integer.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Sample Code

obsClient.setBucketLifecycleConfiguration({
       Bucket : 'bucketname',
       Rules:[
              {ID:'rule1',Prefix:'prefix1',Status:'Enabled',Expiration:{Days: 60}, NoncurrentVersionExpiration:{NoncurrentDays : 60}},
              {ID:'rule2',Prefix:'prefix2',Status:'Enabled',Expiration:{Date: '2018-12-31T00:00:00Z'}}
       ]
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});