Updated on 2023-03-16 GMT+08:00

PUT Bucket lifecycle

API Description

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

Method Definition

ObsClient.setBucketLifecycle

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

NOTE:

The Standard storage class is not supported.

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

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.

Transition, Expiration, NoncurrentVersionTransitions, and NoncurrentVersionExpiration cannot be all null.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Sample Code

obsClient.setBucketLifecycle({
       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);
              }
       }
});