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 | ||
RequestDate | String or Date | Optional | Request time NOTE: When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards. | ||
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 | Mandatory when Days is not set | Date when an object will be transitioned. The value must conform to the ISO8601 standards and must be at 00:00 (UTC time), for example, 2018-01-01T00:00:00Z. | ||
Days | Number | Mandatory when Date is not set | Number of days after which an object will be transitioned since its creation. The value must be a positive integer. | ||
- | Expiration | Object | Optional | Expiration time of an object | |
- | Date | String | Mandatory when Days is not set | Date when an object expires. The value must conform to the ISO8601 standards and must be at 00:00 (UTC time), for example, 2018-01-01T00:00:00Z. | |
Days | Number | Mandatory when Date is not set | Number of days after which an object expires since its creation. The value must be a positive integer. | ||
ID | String | Optional | Rule ID. It is a 1-255 character string. | ||
Prefix | String | Mandatory | Object name prefix identifying one or more 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 this rule is enabled. Possible values are:
| ||
- | 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 transitioned 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 field 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'}}
]
},function (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);
}
}
}); Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.

