全部产品
Search
文档中心

对象存储 OSS:GetBucketLifecycle

更新时间:Apr 28, 2024

调用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不存在或没有配置生命周期规则。