調用GetBucketLifecycle介面查看儲存空間(Bucket)的生命週期規則(Lifecycle)。
注意事項
要查看Bucket的生命週期規則,您必須有oss:GetBucketLifecycle
許可權。具體操作,請參見為RAM使用者授權自訂的權限原則。
請求文法
GET /?lifecycle HTTP/1.1
Host: BucketName.oss.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue
樣本
請求樣本
Get /?lifecycle HTTP/1.1
Host: oss-example.oss.aliyuncs.com
Date: Mon, 14 Apr 2014 01:17:29 GMT
Authorization: OSS qn6q**************:77Dv****************
返回樣本
基於last modify time設定生命週期規則的返回樣本
HTTP/1.1 200 x-oss-request-id: 534B371674E88A4D8906**** Date: Mon, 14 Apr 2014 01:17:29 GMT Connection: keep-alive Content-Length: 255 Server: AliyunOSS <?xml version="1.0" encoding="UTF-8"?> <LifecycleConfiguration> <Rule> <ID>delete after one day</ID> <Prefix>logs1/</Prefix> <Status>Enabled</Status> <Expiration> <Days>1</Days> </Expiration> </Rule> <Rule> <ID>mtime transition1</ID> <Prefix>logs2/</Prefix> <Status>Enabled</Status> <Transition> <Days>30</Days> <StorageClass>IA</StorageClass> </Transition> </Rule> <Rule> <ID>mtime transition2</ID> <Prefix>logs3/</Prefix> <Status>Enabled</Status> <Transition> <Days>30</Days> <StorageClass>IA</StorageClass> <IsAccessTime>false</IsAccessTime> </Transition> </Rule> </LifecycleConfiguration>
基於last access time設定生命週期規則的返回樣本
說明當Bucket存在基於last access time匹配規則的生命週期規則時,返回樣本中會包含AtimeBase元素。該元素表示預設last access time的時間戳記(從1970-01-01 00:00:00 UTC計算起的秒數),即為Bucket開啟訪問跟蹤時間點的時間戳記。
HTTP/1.1 200 x-oss-request-id: **** Date: Mon, 26 Jul 2021 01:17:29 GMT Connection: keep-alive Content-Length: length Server: AliyunOSS <?xml version="1.0" encoding="UTF-8"?> <LifecycleConfiguration> <Rule> <ID>atime transition1</ID> <Prefix>logs1/</Prefix> <Status>Enabled</Status> <Transition> <Days>30</Days> <StorageClass>IA</StorageClass> <IsAccessTime>true</IsAccessTime> <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit> </Transition> <AtimeBase>1631698332</AtimeBase> </Rule> <Rule> <ID>atime transition2</ID> <Prefix>logs2/</Prefix> <Status>Enabled</Status> <NoncurrentVersionTransition> <NoncurrentDays>10</NoncurrentDays> <StorageClass>IA</StorageClass> <IsAccessTime>true</IsAccessTime> <ReturnToStdWhenVisit>false</ReturnToStdWhenVisit> </NoncurrentVersionTransition> <AtimeBase>1631698332</AtimeBase> </Rule> </LifecycleConfiguration>
未設定生命週期規則的返回樣本
HTTP/1.1 404 x-oss-request-id: 534B371674E88A4D8906**** Date: Mon, 14 Apr 2014 01:17:29 GMT Connection: keep-alive Content-Length: 278 Server: AliyunOSS <?xml version="1.0" encoding="UTF-8"?> <Error> <BucketName>oss-example</BucketName> <Code>NoSuchLifecycle</Code> <Message>No Row found in Lifecycle Table.</Message> <RequestId>534B372974E88A4D8906****</RequestId> <HostId> BucketName.oss.example.com</HostId> </Error>
SDK
此介面對應的各語言SDK如下:
錯誤碼
錯誤碼 | HTTP狀態代碼 | 描述 |
AccessDenied | 403 Forbidden | 沒有許可權查看Bucket的生命週期規則。只有Bucket的擁有者才能查看Bucket的生命週期規則。 |
NoSuchBucket或NoSuchLifecycle | 404 Not Found | Bucket不存在或沒有配置生命週期規則。 |