This topic describes how to manage lifecycle rules.

Configure lifecycle rules

The following code provides an example on how to configure lifecycle rules:

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
bucket.lifecycle = [
  LifeCycleRule.new(
    :id => 'rule1', :enabled => true, :prefix => 'foo/', :expiry => 3),
  LifeCycleRule.new(
    :id => 'rule2', :enabled => false, :prefix => 'bar/', :expiry => Date.new(2016, 1, 1))
]
			

View lifecycle rules

The following code provides an example on how to view the lifecycle rules configured for a bucket:

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
rules = bucket.lifecycle
puts rules
			

Delete lifecycle rules

The following code provides an example on how to delete the lifecycle rules configured for a bucket:

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
bucket.lifecycle = []