PutBucketLifecycle
Updated at:2025-11-03
API description
This API is intended to create lifecycle management rules.
Note:
- Only the bucket owner with FULL_CONTROL permission can execute this request.
- PutBucketLifecycle will replace any existing lifecycle rules. To add new rules without losing the existing ones, the request must include both the old and new rules.
Request
-
Request syntax
Plain Text1PUT /?lifecycle HTTP/1.1 2Host: <BucketName>.bj.bcebos.com 3x-bce-date: date 4Content-Length: request-body length 5Content-Type: application/json; charset=utf-8 6Authorization: AuthorizationString 7{ 8 "rule": [{ 9 "id": "rule-id", 10 "status": "enabled", 11 "resource": [ 12 "bucket/prefix/*" 13 ], 14 "condition": { 15 "time": { 16 "dateGreaterThan": "2016-09-07T00:00:00Z" 17 } 18 }, 19 "action": { 20 "name": "DeleteObject" 21 } 22 }] 23} -
Request headers
No special parameters
-
Request parameters
| Rule item | Description | Required or not | Remarks |
|---|---|---|---|
| rule | Rule list | Yes | List of all rules |
| +id | The identifier for the rule. | Yes | Rule IDs must be unique within the same bucket and cannot be duplicated. If the user does not provide an ID, the system will generate one automatically. |
| +status | Status of the rule. | Yes | The value is either enabled or disabled; the rule will not take effect when it is set to disabled. |
| +ExpiredObjectDeleteMarker | Remove the marker for expired objects. | No | The value is either true or false; the rule will not take effect when it is set to false. |
| +resource | The resources to which the rules will apply. | Yes | Example: To apply to objects in samplebucket with the prefix/: samplebucket/prefix/*; to apply to all objects in samplebucket: samplebucket/*. |
| +condition | The conditions on which the rule depends. | Yes | Currently, only the time format is supported; the returned value of the intelligent tiering rule is null. |
| ++time | Time-related constraints. | No | It is implemented via the defined dateGreaterThan. |
| +++dateGreaterThan | Describe relationships related to time. | No | Supports both absolute time ("date") and relative time ("days"). Absolute times (dates) follow the yyyy-mm-ddThh:mm:ssZ format, e.g., 2016-09-07T00:00:00Z, and must be in UTC, ending with 00:00:00 (UTC 0:00). Relative times ("days") adhere to ISO8601, with the minimum granularity being a day. For instance, $(lastModified)+P7D indicates seven days after the object's last-modified time. |
| ++tag | Object tag constraints | No | Example: This rule applies only to objects under the specified prefix that meet the object tag criteria. If the tag is left empty, it applies to all objects by default. |
| ++objectSize | Object size constraints | No | Example: This rule applies only to objects under the specified prefix that meet the object size criteria. If the objectSize is left empty, it applies to all object sizes by default. |
| +action | Actions executed on the specified resource. | Yes | - |
| +name | The name of the operation being executed. | Yes | Values: Transition, DeleteObject, AbortMultipartUpload, IntelligentTiering, NonCurrentVersionDeleteObject, NonCurrentVersionTransition. |
| +storageClass | Storage class of the object | No | When the action is Transition, it can be set. For buckets not distributed across multiple AZs, the values are STANDARD_IA or COLD or ARCHIVE, indicating a transition from the original storage class to infrequent access storage, cold storage, or archive storage. For buckets distributed across multiple AZs, the only value is STANDARD_IA, indicating a transition from the original storage class to infrequent access storage, and the returned value of the intelligent tiering rule is null. |
Response
Example of basic lifecycle management request
-
Request example
Plain Text1PUT /?lifecycle HTTP/1.1 2Host: bucket.bj.bcebos.com 3x-bce-date: 2016-08-16T08:23:49Z 4Content-Length :1324 5Content-Type: application/json; charset=utf-8 6Authorization: AuthorizationString 7{ 8 "rule": [ 9 { 10 "id": "sample-rule-delete-prefix", 11 "status": "enabled", 12 "resource": [ 13 "bucket/prefix/*" 14 ], 15 "condition": { 16 "time": { 17 "dateGreaterThan": "2016-09-07T00:00:00Z" 18 } 19 }, 20 "action": { 21 "name": "DeleteObject" 22 } 23 }, 24 { 25 "id": "sample-rule-transition-prefix", 26 "status": "enabled", 27 "resource": [ 28 "bucket/prefix/*" 29 ], 30 "condition": { 31 "time": { 32 "dateGreaterThan": "$(lastModified)+P7D" 33 } 34 }, 35 "action": { 36 "name": "Transition", 37 "storageClass": "STANDARD_IA" 38 } 39 }, 40 { 41 "id": "sample-rule-abort-multiupload-prefix", 42 "status": "enabled", 43 "resource": [ 44 "bucket/prefix/*" 45 ], 46 "condition": { 47 "time": { 48 "dateGreaterThan": "$(lastModified)+P7D" 49 } 50 }, 51 "action": { 52 "name": "AbortMultipartUpload" 53 } 54 } 55 ] 56} -
Response example
Plain Text1 HTTP/1.1 200 OK 2 x-bce-request-id: 0A49CE4060975EAC 3 Date: Wed, 12 Oct 2016 17:50:00 GMT 4 Content-Length: 0 5 Connection: keep-alive 6 Server: BceBos
Example of intelligent tiering management request
-
Request example
Plain Text1PUT /?lifecycle HTTP/1.1 2Host: bucket.bj.bcebos.com 3x-bce-date: 2022-07-26T17:18:55Z 4Content-Length: 576 5Content-Type: application/json; charset=utf-8 6Authorization: AuthorizationString 7{ 8 "rule": [ 9 { 10 "action": { 11 "name": "IntelligentTiering" 12 }, 13 "id": "sample-rule-intelligent-tiering-prefix", 14 "resource": [ 15 "bucket/*" 16 ], 17 "status": "enabled" 18 }, 19 { 20 "id": "sample-rule-delete-prefix", 21 "status": "enabled", 22 "resource": [ 23 "bucket/prefix/*" 24 ], 25 "condition": { 26 "time": { 27 "dateGreaterThan": "2022-07-27T00:00:00Z" 28 } 29 }, 30 "action": { 31 "name": "DeleteObject" 32 } 33 }, 34 { 35 "id": "sample-rule-abort-multiupload-prefix", 36 "status": "enabled", 37 "resource": [ 38 "bucket/prefix/*" 39 ], 40 "condition": { 41 "time": { 42 "dateGreaterThan": "$(lastModified)+P7D" 43 } 44 }, 45 "action": { 46 "name": "AbortMultipartUpload" 47 } 48 } 49 ] 50} -
Response example
Plain Text1 HTTP/1.1 200 OK 2 x-bce-request-id: FSZ89ESW7DS6FA9 3 Date: Wed, Tue, 26 Jul 2022 05:01:28 GMT 4 Content-Length: 0 5 Connection: keep-alive 6 Server: BceBos
Example of complex lifecycle management request
-
Request example
Plain Text1PUT /?lifecycle HTTP/1.1 2Host: bucket.bj.bcebos.com 3x-bce-date: 2025-02-05T08:23:49Z 4Content-Length :1345 5Content-Type: application/json; charset=utf-8 6Authorization: AuthorizationString 7{ 8 "rule": [{ 9 "id": "rule-id", 10 "status": "enabled", 11 "ExpiredObjectDeleteMarker" :"true", 12 "resource": [ 13 "bucket/prefix/*" 14 ], 15 "condition": { 16 "time": { 17 "dateGreaterThan": "$(lastModified)+P3D" 18 }, 19 "objectSize":{ 20 "minSize":1024, 21 "maxSize":2048 22 }, 23 "tag": { 24 "key1":"value1", 25 "key2":"value2" 26 } 27 }, 28 "action": { 29 "name": "DeleteObject" 30 }, 31 "not":{ // Each rule contains only one not prefix+ not tag, where the prefix and tag must be under the same item 32 "resource": "bucket/prefix/prefix1*", 33 "tag": {"key3":"value3"} 34 } 35 },{ 36 "id": "rule-id2", 37 "status": "enabled", 38 "resource": [ 39 "bucket/*" 40 ], 41 "condition": { 42 "time": { 43 "dateGreaterThan": "$(lastModified)+P5D" 44 }, 45 "tag": { 46 "key1":"value1", 47 "key2":"value2" 48 } 49 }, 50 "action": { 51 "name": "NonCurrentVersionDeleteObject" 52 } 53 }] 54} -
Response example
Plain Text1 HTTP/1.1 200 OK 2 x-bce-request-id: 0A49CE4060975EAC 3 Date: Fri, 5 Feb 2025 08:23:00 GMT 4 Content-Length: 0 5 Connection: keep-alive 6 Server: BceBos
