Updated on 2026-04-23 GMT+08:00

Lifecycle Configuration Examples

If you use APIs or SDKs to create a lifecycle rule, refer to the XML example.

Specifying a Rule with a Single Filter Condition

Example 1: Applying a lifecycle rule to all objects in a bucket

To apply the rule to all objects in the bucket, leave the prefix blank. The following rule transitions all objects in the bucket to the Archive storage class 100 days after they are created.

XML:

1
2
3
4
5
6
7
8
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule</ID>  
        <Prefix></Prefix>
        <Status>Enabled</Status>
            <Days>100</Days>   
    </Rule>
</LifecycleConfiguration>

Example 2: Specifying a filter by object name prefix

The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt.

This rule specifies two actions: transitioning objects to the Infrequent Access storage class 90 days after creation and deleting objects 120 days after creation.

XML:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule</ID>  
        <Status>Enabled</Status>
        <Prefix>texta/</Prefix>
            <Days>90</Days>   
        <Expiration>
            <Days>120</Days>
        </Expiration>
    </Rule>
</LifecycleConfiguration>

Example 3: Specifying a filter by object name prefix to delete objects that were last modified before the given date

The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt.

This rule specifies one action: deleting objects that were last modified before May 30, 2024.

XML:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule</ID>  
        <Status>Enabled</Status>
        <Prefix>texta/</Prefix>
        <Expiration>
            <Date>2024-05-30T00:00:00.000Z</Date>
        </Expiration>
    </Rule>
</LifecycleConfiguration>

Example 4: Specifying a filter by object name prefix to transition objects that were last modified before the given date

The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt.

This rule specifies one action: transitioning objects that were last modified before May 30, 2024 to the Archive storage class.

XML:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule</ID>  
        <Status>Enabled</Status>
        <Prefix>texta/</Prefix>
        <Transition>   
            <Date>2024-05-30T00:00:00.000Z</Date>   
            <StorageClass>COLD</StorageClass>   
        </Transition>  
    </Rule>
</LifecycleConfiguration>

Specifying a Rule with Multiple Filter Conditions

To use multiple filters in a single rule, you must wrap the filters in an And element.

Example 1: Specifying a rule with multiple filter conditions

  • The following rule deletes objects with the texta/ prefix and with tags key1/value1 and key2/value2 120 days after their creation.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <LifecycleConfiguration>
        <Rule>
            <ID>sample-rule</ID>  
            <Filter>
                <And>
                    <Prefix>texta/</Prefix>
                    <Tag>
                        <Key>key1</Key>
                        <Value>value1</Value>
                    </Tag>
                    <Tag>
                        <Key>key2</Key>
                        <Value>value2</Value>
                    </Tag>
                </And>
            </Filter>
            <Status>Enabled</Status>
            <Expiration>
                <Days>120</Days>
            </Expiration>
        </Rule>
    </LifecycleConfiguration>
    

Specifying Multiple Rules

If you want objects to have different lifecycle actions, you can specify multiple rules. The following lifecycle configuration has two rules:

  1. Rule 1 applies to objects with the texta/ prefix. It directs OBS to transition the specified objects to the Archive storage class 120 days after creation and to delete them 360 days after creation.
  2. Rule 2 applies to objects with the textb/ prefix. It directs OBS to transition the specified objects to the Infrequent Access storage class 90 days after creation and to delete them 120 days after creation.

XML:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule1</ID>  
        <Prefix>texta/</Prefix>
        <Status>Enabled</Status>
        <Transition>   
            <Days>120</Days>   
            <StorageClass>COLD</StorageClass>   
        </Transition>  
        <Expiration>
            <Days>360</Days>
        </Expiration>
    </Rule>
    <Rule>
        <ID>sample-rule2</ID>  
        <Prefix>textb/</Prefix>
        <Status>Enabled</Status>
        <Transition>   
            <Days>90</Days>   
            <StorageClass>WARM</StorageClass>   
        </Transition>  
        <Expiration>
            <Days>120</Days>
        </Expiration>
    </Rule>
</LifecycleConfiguration>

Specifying Multiple Rules with Overlapping Filter Conditions

For details about overlapping prefixes and conflicting actions, see Overlapping Lifecycle Rules.

Example 1: Overlapping prefixes (no conflict)

  • Rules: Rule 1 specifies an empty filter (indicating all objects in the bucket). It lets OBS delete all objects 120 days after creation. Rule 2 specifies the typea/ prefix (indicating objects with the typea/ prefix). It lets OBS transition objects to the Archive storage class 90 days after creation.
  • Result: There are no conflicting lifecycle actions. Objects with the typea/ prefix are transitioned to the Archive storage class 90 days after creation and then deleted 120 days after creation.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule1</ID>  
        <Prefix></Prefix>
        <Status>Enabled</Status>
        <Expiration>
            <Days>120</Days>
        </Expiration>
    </Rule>
    <Rule>
        <ID>sample-rule2</ID>  
        <Prefix>typea/</Prefix>
        <Status>Enabled</Status>
        <Transition>   
            <Days>90</Days>   
            <StorageClass>COLD</StorageClass>   
        </Transition>  
    </Rule>
</LifecycleConfiguration>

Example 2: Conflicting prefixes and tags (no conflict)

  • Rules: Rule 1 specifies the ab prefix and a tag (key1/value1). It lets OBS delete objects 120 days after creation. Rule 2 specifies the abc prefix and two tags (key1/value1 and key2/value2). It lets OBS transition objects to the Archive storage class 90 days after creation.
  • Result: There are no conflicting lifecycle actions. Objects with the abc prefix and with tags key1/value1 and key2/value2 are transitioned to the Archive storage class 90 days after creation and then deleted 120 days after creation.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    <LifecycleConfiguration>
        <Rule>
            <ID>sample-rule1</ID>  
            <Filter>
                <And>
                    <Prefix>ab</Prefix>
                    <Tag>
                        <Key>key1</Key>
                        <Value>value1</Value>
                    </Tag>
               </And>
            </Filter>
            <Status>Enabled</Status>
            <Expiration>
                <Days>120</Days>
            </Expiration>
        </Rule>
        <Rule>
            <ID>sample-rule2</ID>  
            <Filter>
                <And>
                    <Prefix>abc</Prefix>
                    <Tag>
                        <Key>key1</Key>
                        <Value>value1</Value>
                    </Tag>
                    <Tag>
                        <Key>key2</Key>
                        <Value>value2</Value>
                    </Tag>
                </And>
            </Filter>
            <Status>Enabled</Status>
            <Transition>   
                <Days>90</Days>   
                <StorageClass>COLD</StorageClass>   
            </Transition>  
        </Rule>
    </LifecycleConfiguration>
    

Example 3: Overlapping prefixes resulting in conflicting lifecycle actions

  • Rules: Rule 1 specifies an empty filter (indicating all objects in the bucket). It lets OBS delete all objects 90 days after creation. Rule 2 specifies the typea/ prefix (indicating objects with the typea/ prefix). It lets OBS transition objects to the Archive storage class 120 days after creation.
  • Result: The lifecycle actions conflict. Such configuration is not allowed.
  •  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <LifecycleConfiguration>
        <Rule>
            <ID>sample-rule1</ID>  
            <Prefix></Prefix>
            <Status>Enabled</Status>
            <Expiration>
                <Days>90</Days>
            </Expiration>
        </Rule>
        <Rule>
            <ID>sample-rule2</ID>  
            <Prefix>typea/</Prefix>
            <Status>Enabled</Status>
            <Transition>   
                <Days>120</Days>   
                <StorageClass>COLD</StorageClass>   
            </Transition>  
        </Rule>
    </LifecycleConfiguration>
    

Example 4: Overlapping prefixes and tags resulting in conflicting lifecycle actions

  • Rules: Rule 1 specifies the abc prefix and a tag (key1/value1). It lets OBS delete objects 90 days after creation. Rule 2 specifies the ab prefix and two tags (key1/value1 and key2/value2). It lets OBS transition objects to the Archive storage class 120 days after creation.
  • Result: The lifecycle actions conflict. Such configuration is not allowed.
  •  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    <LifecycleConfiguration>
        <Rule>
            <ID>sample-rule1</ID>  
            <Filter>
                <And>
                    <Prefix>abc</Prefix>
                    <Tag>
                        <Key>key1</Key>
                        <Value>value1</Value>
                    </Tag>
               </And>
            </Filter>
            <Status>Enabled</Status>
            <Expiration>
                <Days>90</Days>
            </Expiration>
        </Rule>
        <Rule>
            <ID>sample-rule2</ID>  
            <Filter>
                <And>
                    <Prefix>ab</Prefix>
                    <Tag>
                        <Key>key1</Key>
                        <Value>value1</Value>
                    </Tag>
                    <Tag>
                        <Key>key2</Key>
                        <Value>value2</Value>
                    </Tag>
                </And>
            </Filter>
            <Status>Enabled</Status>
            <Transition>   
                 <Days>120</Days>   
                 <StorageClass>COLD</StorageClass>   
            </Transition>  
         </Rule>
    </LifecycleConfiguration>
    

Deleting Fragments

The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt. This rule lets OBS delete object fragments 10 days after generation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
</LifecycleConfiguration>
   <Rule>
        <ID>sample-rule</ID>
        <Prefix>texta/</Prefix>
        <Status>Enabled</Status>
        <AbortIncompleteMultipartUpload>
            <DaysAfterInitiation>10</DaysAfterInitiation>
        </AbortIncompleteMultipartUpload>
    </Rule>
</LifecycleConfiguration>

Specifying a Lifecycle Rule for a Versioning-Enabled/Suspended Bucket

Example 1: Periodically transitioning and deleting historical object versions

The following lifecycle rule specifies prefix prefix1/ as the filter. It applies to objects with the prefix1/ prefix, such as prefix1/file1.txt and prefix1/file2.txt.

This rule specifies two lifecycle actions: transitioning historical object versions to the Archive storage class 20 days after generation and deleting them 30 days after generation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<LifecycleConfiguration>
     <Rule>
         <ID>sample-rule</ID>
         <Prefix>prefix1/</Prefix>
         <Status>Enabled</Status>
         <NoncurrentVersionTransition>
             <NoncurrentDays>20</NoncurrentDays>
             <StorageClass>COLD</StorageClass>
         </NoncurrentVersionTransition>
         <NoncurrentVersionExpiration>
             <NoncurrentDays>30</NoncurrentDays>
         </NoncurrentVersionExpiration>
     </Rule>
 </LifecycleConfiguration>

Example 2: Removing expired delete markers

The following lifecycle rule specifies prefix prefix1/ as the filter. It applies to objects with the prefix1/ prefix, such as prefix1/file1.txt and prefix1/file2.txt.

If all versions of an object with the prefix1/ prefix have been deleted and only one expired delete marker remains, this rule lets OBS remove this expired delete marker.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
</LifecycleConfiguration>
   <Rule>
        <ID>sample-rule</ID>
        <Prefix>prefix1/</Prefix>
        <Status>Enabled</Status>
        <Expiration>
            <ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker>
        </Expiration>
    </Rule>
</LifecycleConfiguration>

Disabling a Lifecycle Rule

The following configuration disables a lifecycle rule. The rule applies to objects with the texta/ prefix in the bucket. It transitions the objects to the Archive storage class 100 days after they are created.

XML:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<LifecycleConfiguration>
    <Rule>
        <ID>sample-rule</ID>  
        <Status>Disabled</Status>
        <Prefix>texta/</Prefix>
        <Transition>   
            <Days>100</Days>   
            <StorageClass>COLD</StorageClass>   
        </Transition>  
    </Rule>
</LifecycleConfiguration>