PutBucketLifecycle
更新时间:2025-04-09
接口描述
本接口用来创建生命周期管理规则。
注意:
- 只有bucket的owner且拥有FULL_CONTROL权限才能够进行此请求。
- PutBucketLifecycle会覆盖原有的生命周期规则, 如果需要在原有规则基础上新增, 需要在请求中携带所有新旧规则。
请求(Request)
-
请求语法
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}
-
请求头域
无特殊参数
-
请求参数
规则项 描述 是否必须 备注 rule 规则的列表 是 所有规则的列表 +id 规则的标识符。 是 同一个bucket内规则id必须唯一,不能重复。如果用户不填系统会自动帮用户生成一个。 +status 规则的状态。 是 取值为 enabled
或disabled
,当规则处于disabled
时规则不生效。+resource 规则对哪些资源生效。 是 举例:对samplebucket里以prefix/为前缀的Object生效: samplebucket/prefix/*
;对samplebucket里所有Object生效:samplebucket/*
。+condition 规则依赖的条件。 是 目前只支持time形式,智能分层规则返回值为null ++time 时间限制条件。 否 通过定义的 dateGreaterThan
实现。+++dateGreaterThan 描述时间关系。 否 支持绝对时间date和相对时间days。绝对时间date格式为yyyy-mm-ddThh:mm:ssZ,eg. 2016-09-07T00:00:00Z。绝对时间为UTC时间, 必须以00:00:00(UTC 0点)结尾;相对时间days的描述遵循ISO8601, 支持的最小时间粒度为天,如: $(lastModified)+P7D表示的时间为object的last-modified之后7天。 ++tag 对象标签限制条件 否 举例: 对这个prefix下的所有满足对象标签规则的Object才生效,如果tag为空,默认应用所有Object。 ++objectSize 对象大小限制条件 否 举例: 对这个prefix下的所有满足对象大小规则的Object才生效,如果objectSize为空,默认应用所有Object的大小都符合条件。 +action 对resource执行的操作动作。 是 - +name 执行的操作名称。 是 取值为 Transition
、DeleteObject
、AbortMultipartUpload
、IntelligentTiering
。+storageClass Object的存储类型 否 action为 Transition
时可以设定,非多AZ bucket的取值为STANDARD_IA
或COLD
或ARCHIVE
,表示从原存储类型转为低频存储或冷存储或归档存储;对于多AZ的bucket,取值只能为STANDARD_IA
,表示从原存储类型转为低频存储,智能分层规则返回null。
响应(Response)
基础生命周期管理请求示例
-
请求示例
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{ 9 "rule": [ 10 { 11 "id": "sample-rule-delete-prefix", 12 "status": "enabled", 13 "resource": [ 14 "bucket/prefix/*" 15 ], 16 "condition": { 17 "time": { 18 "dateGreaterThan": "2016-09-07T00:00:00Z" 19 } 20 }, 21 "action": { 22 "name": "DeleteObject" 23 } 24 }, 25 { 26 "id": "sample-rule-transition-prefix", 27 "status": "enabled", 28 "resource": [ 29 "bucket/prefix/*" 30 ], 31 "condition": { 32 "time": { 33 "dateGreaterThan": "$(lastModified)+P7D" 34 } 35 }, 36 "action": { 37 "name": "Transition", 38 "storageClass": "STANDARD_IA" 39 } 40 }, 41 { 42 "id": "sample-rule-abort-multiupload-prefix", 43 "status": "enabled", 44 "resource": [ 45 "bucket/prefix/*" 46 ], 47 "condition": { 48 "time": { 49 "dateGreaterThan": "$(lastModified)+P7D" 50 } 51 }, 52 "action": { 53 "name": "AbortMultipartUpload" 54 } 55 } 56 ] 57}
-
响应示例
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
智能分层管理请求示例
-
请求示例
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{ 9 "rule": [ 10 { 11 "action": { 12 "name": "IntelligentTiering" 13 }, 14 "id": "sample-rule-intelligent-tiering-prefix", 15 "resource": [ 16 "bucket/*" 17 ], 18 "status": "enabled" 19 }, 20 { 21 "id": "sample-rule-delete-prefix", 22 "status": "enabled", 23 "resource": [ 24 "bucket/prefix/*" 25 ], 26 "condition": { 27 "time": { 28 "dateGreaterThan": "2022-07-27T00:00:00Z" 29 } 30 }, 31 "action": { 32 "name": "DeleteObject" 33 } 34 }, 35 { 36 "id": "sample-rule-abort-multiupload-prefix", 37 "status": "enabled", 38 "resource": [ 39 "bucket/prefix/*" 40 ], 41 "condition": { 42 "time": { 43 "dateGreaterThan": "$(lastModified)+P7D" 44 } 45 }, 46 "action": { 47 "name": "AbortMultipartUpload" 48 } 49 } 50 ] 51}
-
响应示例
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
复杂生命周期管理请求示例
-
请求示例
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{ 9 "rule": [{ 10 "id": "rule-id", 11 "status": "enabled", 12 "resource": [ 13 "bucket/prefix/*" 14 ], 15 "condition": { 16 "time": { 17 "dateGreaterThan": "2016-09-07T00:00:00Z" 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":{ // 一个规则只有一个not prefix+ not tag 其中prefix和tag 必须存在一项 32 "resource": "bucket/prefix/prefix1*", 33 "tag": {"key3":"value3"} 34 } 35 }] 36}
-
响应示例
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