Updated on 2025-12-04 GMT+08:00

GET Bucket lifecycle

API Description

You can use this API to obtain the lifecycle rules of a bucket.

Method Definition

ObsClient.getBucketLifecycle

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

RequestDate

String

or

Date

Optional

Request time

NOTE:

When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Rules

Array

Lifecycle rules of the bucket

-

Transitions

Array

List of object transition policies

-

StorageClass

String

Storage class of the object after transition

Date

String

Date when an object will be transited

Days

String

Number of days after which an object will be transited since its creation

-

Expiration

Object

Expiration time of an object

-

Date

String

Date when an object expires

Days

String

Number of days after which an object expires since its creation

ID

String

Rule ID

Prefix

String

Object name prefix identifying one or more objects to which the rule applies.

Status

String

Whether the rule is enabled

-

NoncurrentVersionTransitions

Array

List of noncurrent object version transition policies

-

StorageClass

String

Storage class of the noncurrent object version after transition

NoncurrentDays

String

Number of days after which an object will be transited since it becomes a noncurrent version

-

NoncurrentVersionExpiration

Object

Expiration time of a noncurrent object version

-

NoncurrentDays

String

Number of days after which an object expires since it becomes a noncurrent version

Sample Code

obsClient.getBucketLifecycle({
       Bucket : 'bucketname'
},function (err, result) {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     for(var i=0;i<result.InterfaceResult.Rules.length;i++){
                           console.log('Rule[' + i + ']:');
                           console.log('ID-->' + result.InterfaceResult.Rules[i]['ID']);
                           console.log('Prefix-->' + result.InterfaceResult.Rules[i]['Prefix']);
                           console.log('Status-->' + result.InterfaceResult.Rules[i]['Status']);
                           console.log('Expiration[Date]-->' + result.InterfaceResult.Rules[i]['Expiration']['Date']);
                           console.log('Expiration[Days]-->' + result.InterfaceResult.Rules[i]['Expiration']['Days']);
                           console.log('NoncurrentVersionExpiration[NoncurrentDays]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionExpiration']['NoncurrentDays']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});