Lifecycle Configuration Examples
This section provides an example of lifecycle configuration. Each example describes how to specify XML in each example solution.
Example 1: Specify a rule.
The following lifecycle configuration contains a rule with two actions, and requests OBS to transit objects whose name prefix is projectdocs/ to Infrequent Access 30 days after creation, to Archive 60 days after creation, and delete them 365 days after creation.
<LifecycleConfiguration>
<Rule>
<ID>Transition and Expiration Rule</ID>
<Prefix>projectdocs</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>365</Days>
</Expiration>
<Transition>
<Days>30</Days>
<StorageClass>WARM</StorageClass>
</Transition>
<Transition>
<Days>60</Days>
<StorageClass>COLD</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration>
Besides time period, you can also specify a date for performing an action. Note that a time period and a date cannot coexist.
If the lifecycle configuration contains more than one action rule, one object may match multiple rules. In this case, the rule priority on OBS is as follows:
-Permanent deletion takes precedence over transition.
-When an object can be transited to Infrequent Access and Archive at the same time, the object will be transited to Archive.
Example 2: Specify a rule applicable to all objects in a bucket.
In the following example, Prefix is left null and Days is set to 0. No prefix indicates that the rule applies to all objects in the bucket. Because Days is set to 0, every object will be transited to Archive at 00:00 (UTC) in the next day after creation.
<LifecycleConfiguration>
<Rule>
<ID>Archive all object same-day upon creation</ID>
<Prefix></Prefix>
<Status>Enabled</Status>
<Transition>
<Days>0</Days>
<StorageClass>COLD</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration>
Example 3: Disable a rule.
The following lifecycle configuration specifies two rules, in which one is disabled. OBS performs no action specified in a disabled rule.
<LifecycleConfiguration>
<Rule>
<ID>30 days log objects expire rule</ID>
<Prefix>logs/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>30</Days>
</Expiration>
</Rule>
<Rule>
<ID>1 year documents expire rule</ID>
<Prefix>documents/</Prefix>
<Status>Disabled</Status>
<Expiration>
<Days>365</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
Example 4: Prefixes can overlap with each other.
The same characters can be used in different prefixes of objects as long as the prefixes specify different actions. The following configuration contains one rule, which specifies that all noncurrent versions (no prefix is specified) in the bucket will be deleted 10 days after the creation. In this way, there are 10 days for a user to restore objects to an earlier version. In the other rule, objects whose name prefix is logs/ are set to expire 30 days after creation.
<LifecycleConfiguration>
<Rule>
<ID>111</ID>
<Prefix></Prefix>
<Status>Enabled</Status>
<NoncurrentVersionExpiration>
<NoncurrentDays>10</NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
<Rule>
<ID>222</ID>
<Prefix>logs/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>30</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
Example 5: Specify a rule containing actions applicable to objects of noncurrent versions.
The following example contains an action applicable to objects of noncurrent versions in a bucket with versioning control enabled.
<LifecycleConfiguration>
<Rule>
<ID>sample-rule</ID>
<Prefix>key-prefix</Prefix>
<Status>Enabled</Status>
<Transition>
<Days>31</Days>
<StorageClass>COLD</StorageClass>
</Transition>
<Expiration>
<Days>730</Days>
</Expiration>
<NoncurrentVersionTransition>
<NoncurrentDays>31</NoncurrentDays>
<StorageClass>COLD</StorageClass>
</NoncurrentVersionTransition>
<NoncurrentVersionExpiration>
<NoncurrentDays>365</NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
</LifecycleConfiguration>
Last Article: Response Elements for Lifecycle Configuration
Next Article: Setting Lifecycle Configuration
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.