All Products
Search
Document Center

Object Storage Service:lifecycle

Last Updated:Dec 26, 2025

Object Storage Service (OSS) lets you manage your objects' lifecycles to optimize storage costs and meet compliance requirements. Create lifecycle rules to automatically perform actions on objects. For example, you can automatically transition infrequently accessed objects to colder storage classes like Archive, or expire (delete) objects after a specified period. These actions can be triggered based on the objects' last modified time or last access time. When you configure rules based on last access time, OSS monitors access patterns to identify and transition less frequently accessed objects, implementing automated data tiering and reducing costs.

Usage notes

  • To create or modify a lifecycle rule, you must have the oss:PutBucketLifecycle permission. To query a lifecycle rule, you must have the oss:GetBucketLifecycle permission. To delete a lifecycle rule, you must have the oss:DeleteBucketLifecycle permission. For more information, see Attach a custom policy to a RAM user.

  • 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.

  • You can use a lifecycle rule to delete objects from a CloudBox bucket. You cannot use a lifecycle rule to change the storage class of objects in a CloudBox bucket.

Create or modify lifecycle rules

You can perform the following steps to create or modify lifecycle rules:

  1. Create a local file and configure lifecycle rules in the XML format in the file.

  2. Use ossutil to read the lifecycle configuration from the local file, and then add the configuration to the specified bucket.

  • Command syntax

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

    The following table describes the parameters in the command syntax.

    Parameter

    Description

    bucketname

    The name of the bucket for which you want to create or modify lifecycle rules.

    local_xml_file

    The name of the local file in which the lifecycle rules are configured. Example: localfile.xml.

  • Examples

    Important

    You can define multiple rules within a single lifecycle configuration. Each rule must have a unique ID. If you submit a configuration that contains rules with duplicate IDs, the operation fails, and HTTP status code 409 is returned.

    1. Create a file named localfile.xml on your local computer and write lifecycle rules into the file.

      Sample lifecycle configurations:

      • Example 1

        The following lifecycle configuration contains two rules. The first rule (ID: test-rule1) applies to all objects (with Prefix set to an empty value) in examplebucket and expires them 365 days after their last modification. The second rule (ID: test-rule2) applies to objects with the test/ prefix and transitions them to the Archive storage class 30 days after their 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

        The following lifecycle rule applies to all objects (with Prefix set to an empty value) in examplebucket and expires matching objects whose last modified time is earlier than 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 named examplebucket, the following rule performs three actions on all objects in the bucket:
        It transitions current object versions to the Infrequent Access (IA) storage class 10 days after they are last modified.
        It transitions noncurrent object versions to the Archive storage class 60 days after they become noncurrent.
        It deletes noncurrent object versions 90 days after they become 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

        The following lifecycle rule applies to objects with the data/ prefix. It transitions these objects to the IA storage class 200 days after they are last accessed. As <ReturnToStdWhenVisit> is set to false, the objects remain in the IA storage class even if they are 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. Run the following command to add the lifecycle configuration to examplebucket:

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

    A successful command returns the elapsed time.

    0.299514(s) elapsed

Query lifecycle rules

  • Command syntax

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

    The following table describes the parameters in the command syntax.

    Parameter

    Description

    bucketname

    The name of the bucket whose lifecycle rules you want to query.

    local_xml_file

    The name of the local file in which you want to store the lifecycle configuration. Example: localfile.xml. If you do not configure this parameter, the lifecycle rules are directly displayed on your screen.

  • Example

    Run the following command to query the lifecycle rules of examplebucket:

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

    The following sample output indicates that the lifecycle configuration is queried and written to the localfile.xml file:

    0.212407(s) elapsed

Delete the lifecycle configuration

  • Command syntax

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

    Run the following command to delete the lifecycle rules configured for examplebucket:

    ossutil lifecycle --method delete oss://examplebucket

    The following sample output indicates that the lifecycle rules are deleted.

    0.530750(s) elapsed

Common options

When running ossutil commands against a bucket in a different region, add the -e option to specify the endpoint of the region in which the bucket is located. When operating on a bucket that belongs to another Alibaba Cloud account, add the -i option to specify the AccessKey ID of the specified account, and add the -k option to specify the AccessKey secret of the specified account.

For example, you can run the following command to create lifecycle rules for examplebucket, which is located in the China (Hangzhou) region and is owned by another Alibaba Cloud account:

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

For more information about common options, see Common options.