All Products
Search
Document Center

Object Storage Service:lifecycle

Last Updated:May 27, 2026

Run the lifecycle command to configure rules that automatically transition objects to colder storage classes or delete them after a specified period, helping you reduce storage costs and meet compliance requirements. Rules trigger based on last modified time or last access time. Access-time-based rules let OSS monitor access patterns and automatically tier cold data to reduce costs.

Usage notes

  • Creating or modifying rules requires oss:PutBucketLifecycle permission. Querying requires oss:GetBucketLifecycle. Deleting requires oss:DeleteBucketLifecycle. For more information, see Grant a custom policy.

  • Before you configure lifecycle rules based on the last modified time or last access time of objects, make sure that you familiarize yourself with this feature. For more information, see Lifecycle rules based on the last modified time and Lifecycle rules based on the last access time.

  • Starting from ossutil 1.6.16, you can use ossutil as the command name directly, regardless of the operating system. For versions earlier than 1.6.16, you must use the operating system-specific executable name. For further instructions, see References for ossutil commands.

  • For more information about lifecycle rules, see Lifecycle.

  • Lifecycle rules can delete objects in CloudBox buckets but cannot change their storage class.

Create or modify lifecycle rules

To create or modify lifecycle rules:

  1. Create a local XML file with lifecycle rules.

  2. Run ossutil to apply the configuration to the target bucket.

  • Command syntax

    ossutil lifecycle --method put oss://bucketname local_xml_file

    Parameters:

    Parameter

    Description

    bucketname

    The target bucket name.

    local_xml_file

    The local XML file containing lifecycle rules. Example: localfile.xml.

  • Examples

    Important

    You can define multiple rules within a single lifecycle configuration. Each rule must have a unique ID. Duplicate IDs cause the operation to fail with HTTP status code 409.

    1. Create a file named localfile.xml and define lifecycle rules.

      Sample configurations:

      • Example 1

        This configuration has two rules. test-rule1 applies to all objects in examplebucket and expires them 365 days after last modification. test-rule2 applies to objects with the test/ prefix and transitions them to Archive 30 days after last modification.

        For information about the storage classes that are supported by lifecycle rules, see Configure lifecycle rules to automatically convert the storage classes of objects.

        <?xml version="1.0" encoding="UTF-8"?>
        <LifecycleConfiguration>
          <Rule>
            <ID>test-rule1</ID>
            <Prefix></Prefix>
            <Status>Enabled</Status>
            <Expiration>
              <Days>365</Days>
            </Expiration>
          </Rule>
          <Rule>
            <ID>test-rule2</ID>
            <Prefix>test/</Prefix>
            <Status>Enabled</Status>
            <Transition>
              <Days>30</Days>
              <StorageClass>Archive</StorageClass>
            </Transition>
          </Rule>
        </LifecycleConfiguration>
      • Example 2

        This rule expires all objects in examplebucket whose last modified time is before December 30, 2019:

        <?xml version="1.0" encoding="UTF-8"?>
        <LifecycleConfiguration>
          <Rule>
            <ID>test-rule0</ID>
            <Prefix></Prefix>
            <Status>Enabled</Status>
            <Expiration>
              <CreatedBeforeDate>2019-12-30T00:00:00.000Z</CreatedBeforeDate>
            </Expiration>
          </Rule>
        </LifecycleConfiguration>
      • Example 3

        For a versioning-enabled bucket examplebucket, this rule:
        Transitions current versions to IA 10 days after last modification.
        Transitions noncurrent versions to Archive 60 days after becoming noncurrent.
        Deletes noncurrent versions 90 days after becoming noncurrent.







        <?xml version="1.0" encoding="UTF-8"?>
        <LifecycleConfiguration>
          <Rule>
            <ID>test-rule3</ID>
            <Prefix></Prefix>
            <Status>Enabled</Status>
            <Transition>
              <Days>10</Days>
              <StorageClass>IA</StorageClass>
            </Transition>
            <NoncurrentVersionTransition>
              <NoncurrentDays>60</NoncurrentDays>
              <StorageClass>Archive</StorageClass>
            </NoncurrentVersionTransition>
            <NoncurrentVersionExpiration>
              <NoncurrentDays>90</NoncurrentDays>
            </NoncurrentVersionExpiration>
          </Rule>
        </LifecycleConfiguration>
      • Example 4

        This rule transitions objects with the data/ prefix to IA 200 days after last access. With <ReturnToStdWhenVisit> set to false, objects remain in IA even if accessed again.

        <?xml version="1.0" encoding="UTF-8"?>
        <LifecycleConfiguration>
          <Rule>
            <ID>test-rule4</ID>
            <Prefix>data/</Prefix>
            <Status>Enabled</Status>
            <Transition>
              <Days>200</Days>
              <StorageClass>IA</StorageClass>
              <IsAccessTime>true</IsAccessTime>
              <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit>
            </Transition>    
          </Rule>  
        </LifecycleConfiguration>

  1. Add the lifecycle configuration to examplebucket:

    ossutil lifecycle --method put oss://examplebucket localfile.xml

    Output on success:

    0.299514(s) elapsed

Query lifecycle rules

  • Command syntax

    ossutil lifecycle --method get oss://bucketname [local_xml_file]

    Parameters:

    Parameter

    Description

    bucketname

    The target bucket name.

    local_xml_file

    The output file for the lifecycle configuration. Example: localfile.xml. If omitted, rules are printed to stdout.

  • Example

    Query the lifecycle rules of examplebucket:

    ossutil lifecycle --method get oss://examplebucket localfile.xml

    Output on success:

    0.212407(s) elapsed

Delete the lifecycle configuration

  • Command syntax

    ossutil lifecycle --method delete oss://bucketname
  • Example

    Delete the lifecycle rules of examplebucket:

    ossutil lifecycle --method delete oss://examplebucket

    Output on success:

    0.530750(s) elapsed

Common options

To access a bucket in a different region, use -e to specify the endpoint. To access a bucket owned by a different Alibaba Cloud account, use -i for the AccessKey ID and -k for the AccessKey secret.

For example, create lifecycle rules for examplebucket in the China (Hangzhou) region, owned by another Alibaba Cloud account:

ossutil lifecycle --method put oss://examplebucket localfile.xml -e oss-cn-hangzhou.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecret

Common options.