Lifecycle#

Object lifecycle management allows you to automatically delete objects from a bucket after their retention period has expired.

PutBucketLifecycleConfiguration#

Specifies rules for deleting objects and their versions from a bucket. Rules for transferring objects between Storage Classes are not supported.

The request overwrites the existing configuration; to keep the previous configuration, add it to the new request.

The request must contain the Content-MD5 header with the MD5 hash of the passed configuration (request body) in Base64 encoding.

Sample Request#

Request
PUT /bucket1/?lifecycle=null HTTP/1.1
Host: s3.k2.cloud
Content-MD5: B+uE7Xf0n6K5qORbVGqzAw==
X-Amz-Content-Sha256: beaead3198f7da1e70d03ab969765e0821b24fc913697e929e726aeaebf0eba3
X-Amz-Date: 20220601T081208Z
Authorization: AWS4-HMAC-SHA256 Credential=project:user@company/20220601/{region}/s3/aws4_request, SignedHeaders=content-md5;host;x-amz-content-sha256;x-amz-date, Signature=24eceb4f2f3d83c606966ca631e240c4d33cc3949a63f76eb99d99fef06b2fef
Content-Type: application/xml
Content-Length: 400

<LifecycleConfiguration>
 <Rule>
    <ID>ObjectExpiration</ID>
    <Filter>
       <Prefix>logs/</Prefix>
    </Filter>
    <Status>Enabled</Status>
    <Expiration>
       <Days>365</Days></Expiration>
 </Rule>
 <Rule>
    <ID>DeleteNonCurrent</ID>
    <Filter>
       <Prefix>logs/</Prefix>
    </Filter>
       <Status>Enabled</Status>
    <NoncurrentVersionExpiration>
       <NoncurrentDays>100</NoncurrentDays>
    </NoncurrentVersionExpiration>
  </Rule>
</LifecycleConfiguration>

Sample Response#

Response
HTTP/1.1 200 OK
x-amz-request-id: tx000000000000007feef9e-00629724ec-41e627a3-default
content-type: application-xml
content-length: 0
date: Wed, 01 Jun 2022 08:35:56 GMT

GetBucketLifecycleConfiguration#

Returns the bucket lifecycle configuration.

Sample Request#

Request
GET /bucket1?lifecycle=null HTTP/1.1
Host: s3.k2.cloud
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20220601T114555Z
Authorization: AWS4-HMAC-SHA256 Credential=project:user@company/20220601/{region}/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=7f49aa189dd0b80285149fe3f979b166a9be8ccf2ef7da2a394ac98bd2056d93

Sample Response#

Response
HTTP/1.1 200 OK
x-amz-request-id: tx0000000000000081d8990-0062975173-41e627a3-default
content-type: application-xml
content-length: 274
date: Wed, 01 Jun 2022 11:45:55 GMT

<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Rule>
        <ID>LogExpiration</ID>
        <Filter>
            <Prefix>logs/</Prefix>
        </Filter>
        <Status>Enabled</Status>
        <Expiration>
            <Days>365</Days>
        </Expiration>
    </Rule>
</LifecycleConfiguration>

DeleteBucketLifecycleConfiguration#

Deletes the bucket lifecycle configuration.

Sample Request#

Request
DELETE /bucket1/?lifecycle=null HTTP/1.1
Host: s3.k2.cloud
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
X-Amz-Date: 20220601T115410Z
Authorization: AWS4-HMAC-SHA256 Credential=project:user@company/20220601/{region}/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=6c7c533abb88c693fbe500ca17c505219e725e883254e274f07a52d309ec7f37

Sample Response#

Response
HTTP/1.1 204 No Content
x-amz-request-id: tx000000000000008240d6f-0062975362-40173986-default
content-type: application-xml
date: Wed, 01 Jun 2022 11:54:10 GMT