PUT Bucket lifecycle

OBS supports periodic deletion of objects in a bucket based on a specified rule. This is implemented in lifecycle configuration. After the bucket lifecycle is set, OBS automatically deletes objects at the time specified in this operation. This operation can be used to delete:

  • Periodically uploaded files: Some periodically uploaded files need to be retained for only one week or one month.

  • Documents that are seldom accessed after a certain period of time. These documents may be archived for another period of time and be deleted then.

This operation is used to create or update the lifecycle configuration of a bucket.

Only users granted the s3:PutLifecycleConfiguration permission can create or update the bucket lifecycle configuration. By default, only the bucket owner can set the bucket lifecycle configuration. The bucket owner can allow other users to set the bucket lifecycle configuration by granting them the permission.

The lifecycle configuration supports periodic deletion of objects. If you want to prevent a user from deleting objects, disable the following permissions:

  • s3:DeleteObject

  • s3:DeleteObjectVersion

  • s3:PutLifecycleConfiguration

If you want to prevent a user configuring a bucket lifecycle, revoke the s3:PutLifecycleConfiguration permission from the user.

Request Syntax

PUT /?lifecycle HTTP/1.1
User-Agent: user-agent
Host: bucketname.obs.example.com
Content-Length: length
Date: date
Authorization: authorization
Content-MD5: MD5
Expect: expect

<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
 <Rule>
  <ID>id</ID>
  <Prefix>prefix</Prefix>
  <Status>status</Status>
  <Expiration>
   <Days>365</Days>
  </Expiration>
  <NoncurrentVersionExpiration>
   <NoncurrentDays>365</NoncurrentDays>
  </NoncurrentVersionExpiration>
 </Rule>
</LifecycleConfiguration>

Request Parameters

This request involves no parameters.

Request Headers

The request uses one header, as described in Table 1.

Table 1 Request header

Header

Description

Remarks

Content-MD5

The MD5 digest string of the message body is calculated according to the RFC 1864 standard. That is, calculate the 128-bit binary array (the message header data encrypted with MD5) first, and then use Base 64 encoding to convert the binary data to a character string.

Type: String

Example: n58IG6hfM7vqI4K0vnWpog==

Mandatory

x-amz-security-token

Header field used to identify the request of a federated user. When the federal authentication function is enabled, users sending such requests are identified as federated users.

Type: string

Optional. This parameter must be carried in the request sent by federated users.

Request Elements

In this request, you need to specify the lifecycle configuration in the request body using the elements described in Table 2.

Table 2 Request elements for lifecycle configuration

Element

Description

Remarks

Date

Indicates when the specified rule takes effect (applicable to the latest object version).

The date value must conform to ISO 8601 format. The time is always midnight UTC.

Type: String

Ancestor: Expiration

Mandatory if the Days parameter is absent.

Days

Indicates the number of days after object creation when the specified rule takes effect.

Type: Positive integer

Ancestor: Expiration

Mandatory if the Date parameter is absent.

Expiration

Indicates the container for the object expiration rule.

Type: XML

Children: Date or Days

Ancestor: Rule

Mandatory

ID

Indicates the unique identifier of a rule. The value can contain a maximum of 255 characters.

Type: String

Ancestor: Rule

Optional

LifecycleConfiguration

Indicates the container for lifecycle rules. You can add multiple rules. The total size of the rules cannot exceed 20 KB.

Type: XML

Children: Rule

Ancestor: None

Mandatory

NoncurrentDays

Indicates the number of days after object is noncurrent when the specified rule takes effect.

Type: Positive integer

Ancestor: NoncurrentVersionExpiration

Mandatory if the NoncurrentVersionExpiration parameter is present.

NoncurrentVersionExpiration

Indicates the container for the noncurrent object expiration rule. You set this lifecycle configuration action on a bucket that has versioning enabled (or suspended) to request that OBS delete noncurrent object versions which meet the expiration rule.

Type: XML

Children: NoncurrentDays

Ancestor: Rule

Mandatory if Expiration are absent.

Prefix

Indicates the object key prefix identifying one or more objects to which the rule applies.

Type: String

Ancestor: Rule

Mandatory

Rule

Indicates the container for lifecycle rules.

Type: Container

Ancestor: LifecycleConfiguration

Mandatory

Status

Indicates whether the rule is enabled.

Type: String

Ancestor: Rule

Valid Values: Enabled, Disabled

Mandatory

If the multi-version of a bucket is enabled or suspended, you can set NoncurrentVersionExpiration to control the lifecycle of historical object versions. The lifecycle of a historical version depends on the time when the version becomes a historical one, that is, the version is overwritten by a new version (NoncurrentDays).

In deletion circumstances, if NoncurrentDays is 1, a version can only be deleted one day after it has become a historical version. For example, the V1 version of object A is created on the first day of a month, and its new version V2 is uploaded on the fifth day of the month. Then V1 becomes a historical version. One day later, that is, when the 0 o'clock of the seventh day comes, V1 expires. (Remarks: There is a delay of less than 48 hours for such a deletion upon object expiration.)

The following lists the background processing for when the multi-version of a bucket is enabled or suspended and the object of the latest version meets expiration rules:

  • The multi-version of the bucket is enabled:

    • If the object of the latest version is not deletemarker, a new deletemarker is generated for the object.

    • If the object of the latest version is deletemarker and the object has this version only, the version will be deleted.

    • If the object of the latest version is deletemarker and the object has other versions, all versions of the object remain unchanged.

  • The multi-version of the bucket is suspended:

    • If the latest version is not null, deletemarker of a null version will be generated.

    • If the latest version is null, the null version will be overwritten by deletemarker of a new null version.

Response Syntax

HTTP/1.1 status_code
Server: Server Name
x-amz-request-id: request id
x-amz-id-2: id
x-reserved: amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc
Date: date
Content-Length: length

Response Headers

This response uses common headers. For details about common response headers, see section Common Response Headers.

Response elements

This response involves no elements.

Error Responses

No special error responses are returned. For details about error responses, see Table 1.

Sample Request 1

PUT /?lifecycle HTTP/1.1
 User-Agent: curl/7.29.0
 Host: bucketname.obs.example.com
 Date: Thu, 05 Sep 2013 09:35:44 +0000
 Authorization: AWS B9A70C60A39C4D551A16:MOO0dUPmAAEXEe0/z+Q9LCx1Vzc=
 Content-MD5: Sa2ttwkV/+XRCwEHg4N8ow==
 Content-Length: 423
 Expect: 100-continue

<LifecycleConfiguration>
<Rule>
<ID>delete-2-days</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>365</Days>
</Expiration>
<NoncurrentVersionExpiration>
<NoncurrentDays>365</NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
</LifecycleConfiguration>

Sample Response 1

HTTP/1.1 200 OK
 Date: Thu, 05 Sep 2013 09:35:44 GMT
 Server: OBS
 x-amz-request-id: 90E2BA0A420C00000140ED7A369007A2
 x-amz-id-2: t35S98JCFKUMswCPZCk+UTi/VOoiSenzi5J6wnoKCIMfXUsKYGgU5+daiWAYiY/8
 x-reserved: amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc
 Content-Length: 0

Sample Request 2

PUT /?lifecycle HTTP/1.1
User-Agent: curl/7.29.0
Host: bucketname.obs.example.comDate: Thu, 05 Sep 2015 09:35:44 +0000
Authorization: AWS B9A70C60A39C4D551A16:MOO0dUPmAAEXEe0/z+Q9LCx1Vzc=
Content-MD5: Sa2ttwkV/+XRCwEHg4N8ow==
Content-Length: 423
Expect: 100-continue
<LifecycleConfiguration>
<Rule>
<ID>delete-2-days</ID>
<Prefix>test/</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>365</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>

Sample Response 2

HTTP/1.1 200 OK
Date: Thu, 05 Sep 2015 09:35:44 GMT
x-amz-request-id: 90E2BA0A420C00000140ED7A369007A2
x-amz-id-2: t35S98JCFKUMswCPZCk+UTi/VOoiSenzi5J6wnoKCIMfXUsKYGgU5+daiWAYiY/8
x-reserved: amazon, aws and amazon web services are trademarks or registered trademarks of Amazon Technologies, Inc
Content-Length: 0