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.
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 |
PUT /?lifecycle HTTP/1.1 Host: bucketname.obs.region.myhuaweicloud.com Content-Length: length Date: date Authorization: authorization Content-SHA256: SHA256 <?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> |
Request Parameters
This request contains no parameters.
Request Headers
Table 1 lists the request headers.
Parameter |
Mandatory (Yes/No) |
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= Range: None Default value: None |
Request Elements
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 (Yes/No) |
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: None Default value: None |
Rule |
Yes |
XML |
Definition: A specific lifecycle rule. Constraints: None Range: For details, see Table 3. Default value: None |
Parameter |
Mandatory (Yes/No) |
Type |
Description |
---|---|---|---|
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: None |
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: None |
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: None |
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: None |
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: None |
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: None |
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: None |
Prefix |
Yes |
String |
Definition: Object name prefix. It identifies the objects the rule applies to. Constraints:
Range: The value is a string of 0 to 255 characters. Default value: None |
Status |
Yes |
String |
Definition: Whether the rule is enabled Constraints: None Range:
Default value: None |
Parameter |
Mandatory (Yes/No) |
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: None |
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 0 to 2147483647. Default value: None |
StorageClass |
Yes if the Transition or NoncurrentVersionTransition element is present. |
String |
Definition: The storage class to which the object is transitioned. Constraints: None Range:
Default value: None |
Parameter |
Mandatory (Yes/No) |
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: None |
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 0 to 2147483647. Default value: None |
Parameter |
Mandatory (Yes/No) |
Type |
Description |
---|---|---|---|
NoncurrentDays |
Yes if the NoncurrentVersionExpiration or NoncurrentVersionTransition element is present. |
Integer |
Definition: Number of days an object is historical before the specified rule takes effect Constraints: This parameter is only available for historical object versions. Range:
Default value: None |
StorageClass |
Yes if the Transition or NoncurrentVersionTransition element is present. |
String |
Definition: The storage class to which the object is transitioned. Constraints: None Range:
Default value: None |
Parameter |
Mandatory (Yes/No) |
Type |
Description |
---|---|---|---|
NoncurrentDays |
Yes if the NoncurrentVersionExpiration or NoncurrentVersionTransition element is present. |
Integer |
Definition: Number of days an object is 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 0 to 2147483647. Default value: None |
Parameter |
Mandatory (Yes/No) |
Type |
Description |
---|---|---|---|
DaysAfterInitiation |
Yes if the AbortIncompleteMultipartUpload element is present. |
Integer |
Definition: Number of days fragments are present before being deleted Constraints: None Range: The value is an integer ranging from 0 to 2147483647. Default value: None |
Parameter |
Mandatory (Yes/No) |
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: None |
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: None |
Parameter |
Mandatory (Yes/No) |
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: None |
Parameter |
Mandatory (Yes/No) |
Type |
Description |
---|---|---|---|
Key |
Yes if Tag is present. |
String |
Definition: The key of the tag. Constraints: None Range: The key name is case-sensitive and must be unique. It consists of 0 to 128 characters and cannot be blank. The following characters are not allowed: =*<>\,|/?!; Default value: None |
Value |
Yes if Tag is present. |
String |
Definition: The value of the tag. Constraints: None Range: The key value is case-sensitive and consists of 0 to 255 characters. It can be blank and cannot contain the following characters: =*<>\,|?!; Default value: None |
Response Syntax
1 2 3 |
HTTP/1.1 status_code Date: date Content-Length: length |
Response Headers
The response to the request uses common headers. For details, see Table 1.
Response Elements
This response contains no elements.
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 |
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-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