Configuring Bucket Lifecycle Rules
Functions
You can configure lifecycle rules to automatically delete objects or transition objects between storage classes. For details about lifecycle rules, see Lifecycle.
Constraints
- A lifecycle rule can use prefixes and object tags as filters, but it cannot use wildcards, suffixes, or regular expressions.
- A bucket can have an unlimited number of lifecycle rules, but the XML file of all its rules cannot exceed 20 KB.
- A maximum of 20 lifecycle rules can be configured for a parallel file system.
- If you want to modify the lifecycle rules of a bucket, you need to add rules. For example, if a bucket has already had Rule 1, you can add Rule 2 by performing the following operations:
- Call GetBucketLifecycle to obtain Rule 1.
- Add Rule 2.
- Call PutBucketLifecycle to update the lifecycle rule to Rule 1 and Rule 2.
Authorization Information
To call this API, you must be the bucket owner or have the permission to configure bucket lifecycle rules. You are advised to use IAM or bucket policies for authorization. For details about OBS authorization methods, see Differences Between OBS Permissions Control Methods.
- If you use IAM for authorization, you need to use either role/policy-based authorization or identity policy-based authorization and configure the required permissions:
- If you use role/policy-based authorization (IAM v3 APIs in the old IAM version), you need to grant the obs:bucket:PutLifecycleConfiguration permission. For details, see Creating a Custom IAM Policy.
- If you use identity policy-based authorization (IAM v5 APIs in the new IAM version), you need to grant the obs:bucket:putLifecycleConfiguration permission, as shown in the following table. For details, see Creating a Custom IAM Identity Policy.
Action
Access Level
Resource Type (*: Required)
Dependencies
obs:bucket:putLifecycleConfiguration
Write
bucket *
-
-
-
- obs:EpochTime
- obs:SourceIp
- obs:TlsVersion
- obs:CustomDomain
- If you use bucket policies for authorization, you need to grant the obs:bucket:PutLifecycleConfiguration permission. For details, see Creating a Custom Bucket Policy.
Request Syntax
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 40 41 42 43 | PUT /?lifecycle HTTP/1.1 Host: bucketname.obs.region.myhuaweicloud.com Content-Length: length Date: date Authorization: authorization Content-SHA256: SHA256 Content-MD5: MD5 <?xml version="1.0" encoding="UTF-8"?> <LifecycleConfiguration> <Rule> <ID>id</ID> <Filter> <And> <Prefix>prefix</Prefix> <Tag><Key>key1</Key><Value>value1</Value></Tag> <Tag><Key>key2</Key><Value>value2</Value></Tag> </And> </Filter> <Status>status</Status> <Expiration> <Days>days</Days> </Expiration> <NoncurrentVersionExpiration> <NoncurrentDays>days</NoncurrentDays> </NoncurrentVersionExpiration> <Transition> <Days>30</Days> <StorageClass>WARM</StorageClass> </Transition> <Transition> <Days>60</Days> <StorageClass>COLD</StorageClass> </Transition> <NoncurrentVersionTransition> <NoncurrentDays>30</NoncurrentDays> <StorageClass>WARM</StorageClass> </NoncurrentVersionTransition> <NoncurrentVersionTransition> <NoncurrentDays>60</NoncurrentDays> <StorageClass>COLD</StorageClass> </NoncurrentVersionTransition> </Rule> </LifecycleConfiguration> |
URI Parameters
This request contains no message parameters.
Request Headers
Table 1 lists the request headers.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Content-SHA256 | Yes | String | Definition SHA-256 digest string of the message body, that is, the string obtained after the 256-bit SHA-256 value of the message body is encoded using Base64. Example: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI= Constraints You can also configure the Content-MD5 header whose value is the Base64-encoded result of the 128-bit MD5 of the message. Configure either Content-MD5 or Content-SHA256. Range N/A Default Value N/A |
| Content-MD5 | Yes | String | Definition Base64-encoded 128-bit MD5 digest of the message according to RFC 1864. Example: n58IG6hfM7vqI4K0vnWpog== Constraints You can also configure the Content-SHA256 header whose value is the Base64-encoded result of the 256-bit SHA256 of the message. Configure either Content-MD5 or Content-SHA256. Range N/A Default Value N/A |
Request Body
In this request body, you need to specify the lifecycle configuration in XML format. Table 2 describes the specific XML configuration elements. For details, see Lifecycle Elements.
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| LifecycleConfiguration | Yes | XML | Definition Lifecycle rules. Multiple rules can be configured. LifecycleConfiguration is the parent node of Rule. Constraints The total size of the configuration message body cannot exceed 20 KB. Range N/A Default Value N/A |
| Rule | Yes | XML | Definition A specific lifecycle rule. Constraints N/A Range For details, see Table 3. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| ID | No | String | Definition ID of a rule. Constraints Only letters, digits, periods (.), underscores (_), and hyphens (-) are allowed. Range The value is a string of 0 to 255 characters. Default Value N/A |
| Filter | Either Filter or Prefix can be configured at the same level under Rule. Prefix can be a child node of Filter. | XML | Definition A specific filter. The lifecycle rule will apply to the objects matching this filter in a bucket. You can filter objects by object name prefix, object tag, or a combination of them. Constraints If there are multiple filtering criteria, use the AND logic to combine them. Range For details, see Table 9. Default Value N/A |
| Prefix | Yes | String | Definition Object name prefix. It identifies the objects the rule applies to. Constraints
Range The value must contain 0 to 1,024 characters. Default Value N/A |
| Transition | Yes if the NoncurrentVersionTransition, Expiration, AbortIncompleteMultipartUpload, and NoncurrentVersionExpiration elements are absent. | XML | Definition Transition time and the object storage class after transition Constraints This parameter is only available for the latest object version. Range For details, see Table 4. Default Value N/A |
| Expiration | Yes if Transition, NoncurrentVersionTransition, AbortIncompleteMultipartUpload, and NoncurrentVersionExpiration are absent. | XML | Definition Expiration time. Constraints This parameter is only available for the latest object version. Range For details, see Table 5. Default Value N/A |
| NoncurrentVersionTransition | Yes if the Transition, Expiration, AbortIncompleteMultipartUpload, and NoncurrentVersionExpiration elements are absent. | XML | Definition Transition time and the object storage class after transition Constraints This parameter is only available for historical object versions. Range For details, see Table 6. Default Value N/A |
| NoncurrentVersionExpiration | No | XML | Definition Expiration time of objects' historical versions. If versioning is enabled or suspended for a bucket, you can set this parameter to delete historical versions of objects that match the lifecycle rule. Constraints This parameter is only available for historical object versions. Range For details, see Table 7. Default Value N/A |
| AbortIncompleteMultipartUpload | Yes if the Transition, Expiration, NoncurrentVersionExpiration, and NoncurrentVersionTransition elements are absent. | XML | Definition Expiration attribute of fragments in an unassembled multipart task. Constraints Tag-based filtering is not supported. Range For details, see Table 8. Default Value N/A |
| Status | Yes | String | Definition Whether the rule is enabled Constraints N/A Range
Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Date | Yes if the Days element is absent. | String | Definition Specifies that OBS executes lifecycle rules for objects before the specified date. Constraints The date must be compliant with the ISO8601 format, and the time must be compliant with the UTC format of 00:00:00. For example, 2018-01-01T00:00:00.000Z indicates that objects whose last modification time is earlier than 2018-01-01T00:00:00.000Z are deleted or transitioned to another storage class. Objects whose last modification time is equal to or later than the specified time are not deleted or transitioned to another storage class. Range Character string in the date format. Default Value N/A |
| Days | Yes if the Date element is absent. | Integer | Definition Number of days (since the last update was made to the object) after which the lifecycle rule takes effect Constraints This parameter is only available for the latest object version. Range The value is an integer ranging from 1 to 2147483647. Default Value N/A |
| StorageClass | Yes if the Transition or NoncurrentVersionTransition element is present. | String | Definition The storage class to which the object is transitioned. Constraints N/A Range
Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Date | Yes if the Days element is absent. | String | Definition Specifies that OBS executes lifecycle rules for objects before the specified date. Constraints The date must be compliant with the ISO8601 format, and the time must be compliant with the UTC format of 00:00:00. For example, 2018-01-01T00:00:00.000Z indicates that objects whose last modification time is earlier than 2018-01-01T00:00:00.000Z are deleted or transitioned to another storage class. Objects whose last modification time is equal to or later than the specified time are not deleted or transitioned to another storage class. Range Character string in the date format. Default Value N/A |
| Days | Yes if the Date element is absent. | Integer | Definition Number of days (since the last update was made to the object) after which the lifecycle rule takes effect Constraints This parameter is only available for the latest object version. Range The value is an integer ranging from 1 to 2147483647. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| NoncurrentDays | Yes if the NoncurrentVersionExpiration or NoncurrentVersionTransition element is present. | Integer | Definition Number of days an object stays historical before the specified rule takes effect Constraints This parameter is only available for historical object versions. Range
Default Value N/A |
| StorageClass | Yes if the Transition or NoncurrentVersionTransition element is present. | String | Definition The storage class to which the object is transitioned. Constraints N/A Range
Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| NoncurrentDays | Yes if the NoncurrentVersionExpiration or NoncurrentVersionTransition element is present. | Integer | Definition Number of days an object stays historical before the specified rule takes effect Constraints This parameter is only available for historical object versions. Range The value is an integer ranging from 1 to 2147483647. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| DaysAfterInitiation | Yes if the AbortIncompleteMultipartUpload element is present. | Integer | Definition Number of days fragments are present before being deleted Constraints N/A Range The value is an integer ranging from 1 to 2147483647. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| And | Yes if there are multiple Prefix and Tag rules. | XML | Definition The And logic among filtering criteria. The And logic can be used when both the object name prefix and object tag are used or multiple object tags are used. Constraints
Range For details, see Table 10. Default Value N/A |
| Tag | No | Container | Definition Object tag, which is used to identify what objects match the rule. Constraints
Range For details, see Table 11. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Tag | No | Container | Definition Tag element, which is used to identify the objects that can match the current rule. Constraints
Range For details, see Table 11. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Key | Yes if Tag is present. | String | Definition The key of the tag. Constraints N/A Range The key name is case-sensitive and must be unique. It consists of 1 to 128 characters and cannot be left blank. The following characters are not allowed: =*<>\,|/?!; Default Value N/A |
| Value | Yes if Tag is present. | String | Definition The value of the tag. Constraints N/A Range The tag value is case-sensitive and consists of 0 to 255 characters. It can be blank and cannot contain the following characters: =*<>\,|?!; Default Value N/A |
Response Syntax
1 2 3 | HTTP/1.1 status_code Date: date Content-Length: length |
Response Headers
This response uses common headers. For details, see Table 1.
Response Body
The response of this API does not contain a response body.
Error Responses
No special error responses are returned. For details about error responses, see Table 2.
Sample Request
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 40 41 42 43 44 45 46 47 | PUT /?lifecycle HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Accept: */* Date: WED, 01 Jul 2015 03:05:34 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:DpSAlmLX/BTdjxU5HOEwflhM0WI= Content-SHA256: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI= Content-MD5: ujCZn5p3fmczNiQQxdsGaQ== Content-Length: 919 <?xml version="1.0" encoding="utf-8"?> <LifecycleConfiguration> <Rule> <ID>lifecycle-rule-id</ID> <Filter> <And> <Prefix>prefix</Prefix> <Tag><Key>key1</Key><Value>value1</Value></Tag> <Tag><Key>key2</Key><Value>value2</Value></Tag> </And> </Filter> <Status>Enabled</Status> <Expiration> <Days>70</Days> </Expiration> <NoncurrentVersionExpiration> <NoncurrentDays>70</NoncurrentDays> </NoncurrentVersionExpiration> <Transition> <Days>30</Days> <StorageClass>WARM</StorageClass> </Transition> <Transition> <Days>60</Days> <StorageClass>COLD</StorageClass> </Transition> <NoncurrentVersionTransition> <NoncurrentDays>30</NoncurrentDays> <StorageClass>WARM</StorageClass> </NoncurrentVersionTransition> <NoncurrentVersionTransition> <NoncurrentDays>60</NoncurrentDays> <StorageClass>COLD</StorageClass> </NoncurrentVersionTransition> </Rule> </LifecycleConfiguration> |
Sample Response
1 2 3 4 5 6 | HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF26000001643670AC06E7B9A7767921 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSvK6z8HV6nrJh49gsB5vqzpgtohkiFm Date: WED, 01 Jul 2015 03:05:34 GMT Content-Length: 0 |
Sample Request: Transitioning the Objects' Storage Class Only
PUT /?lifecycle HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: WED, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
Content-MD5: b67aDumlm/b+5iev6+sRYw==
<LifecycleConfiguration>
<Rule>
<ID>lifecycle-rule-id</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<Transition>
<Days>30</Days>
<StorageClass>WARM</StorageClass>
</Transition>
<Transition>
<Days>60</Days>
<StorageClass>COLD</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration> Sample Response: Transitioning the Objects' Storage Class Only
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSZbDadL1f7fYU44bvRLvc0l6D10+wzG x-obs-request-id: 0000018A2BCBB3ABD3046B99E3ED2E30 Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Deleting Expired Objects Only
PUT /?lifecycle HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: WED, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
Content-MD5: tt0IizQ7YSTFtMJ3sie6qA==
<LifecycleConfiguration>
<Rule>
<ID>lifecycle-rule-id</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>70</Days>
</Expiration>
</Rule>
</LifecycleConfiguration> Sample Response: Deleting Expired Objects Only
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSfpG6nArWY7cM7rB3+GbvO13XJPx9g4 x-obs-request-id: 0000018A2BD6BB02D30426F6E4A1FBA2 Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Transitioning the Objects' Storage Class and Then Deleting the Objects
PUT /?lifecycle HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: WED, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
Content-MD5: 9CJYqNUbXEVhhawEx0ICRw==
<LifecycleConfiguration>
<Rule>
<ID>lifecycle-rule-id</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>70</Days>
</Expiration>
<Transition>
<Days>30</Days>
<StorageClass>WARM</StorageClass>
</Transition>
<Transition>
<Days>60</Days>
<StorageClass>COLD</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration> Sample Response: Transitioning the Objects' Storage Class and Then Deleting the Objects
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSMYkLcGTyUsgSJe2Rdsg2P8JwMsJV6n x-obs-request-id: 0000018A2BDA0816D2877F5D5622F0BA Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Deleting Historical Object Versions and Delete Markers
PUT /?lifecycle HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Host: examplebucket.obs.region.myhuaweicloud.com
Date: WED, 01 Jul 2015 02:37:22 GMT
Content-Type: application/xml
Content-MD5: SGAUB+2hLUAWV5IJ69xU+Q==
<LifecycleConfiguration>
<Rule>
<ID>lifecycle-rule-id</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<NoncurrentVersionExpiration>
<NoncurrentDays>70</NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
</LifecycleConfiguration> Sample Response: Deleting Historical Object Versions and Delete Markers
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSZbDadL1f7fYU44bvRLvc0l6D10+wzG x-obs-request-id: 0000018A2BCBB3ABD3046B99E3ED2E30 Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Deleting Fragments
PUT /?lifecycle HTTP/1.1
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4=
User-Agent: curl/7.29.0
Date: Thu, 24 Apr 2025 14:28:22 GMT
Content-Type: application/xml
Content-MD5: PBgGafte2ACjUwYxdJA47Q==
<LifecycleConfiguration>
<Rule>
<ID>lifecycle-rule-id</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<AbortIncompleteMultipartUpload>
<DaysAfterInitiation>10</DaysAfterInitiation>
</AbortIncompleteMultipartUpload>
</Rule>
</LifecycleConfiguration> Sample Response: Deleting Fragments
HTTP/1.1 200 OK x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCTlN+glNMVGtTicAnVXkTVDjR5xKSLuH x-obs-request-id: 0000018A2BE86742D2C6989CA79E136C Server: OBS Content-Length: 0 Date: Thu, 24 Apr 2025 14:28:23 GMT
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot