PUT Bucket Lifecycle

You can perform this operation to delete objects from a bucket at a specified time. 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 log files. Some periodically uploaded log files need to be retained for only one week or one month.
  • Documents that are seldom accessed after a certain period of time. You can archive these documents before deleting them.

You can perform this operation 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 enables OBS to delete objects at a specified time. To prevent a user from deleting objects whose bucket's lifecycle has been set, the following permissions granted to the user must be revoked:

  • s3:DeleteObject
  • s3:DeleteObjectVersion
  • s3:PutLifecycleConfiguration

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

Request Syntax

PUT /?lifecycle HTTP/1.1
Host: bucketname.obs.cn-north-1.myhwclouds.com
Content-Length: length
Date: date
Authorization: authorization
Content-MD5: MD5

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

Request Parameters

This request contains no parameter.

Request Headers

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

Table 1 Request header

Header

Description

Required or Optional

Content-MD5

Indicates the base64-encoded 128-bit MD5 digest of the message according to RFC 1864.

Type: string

Example: n58IG6hfM7vqI4K0vnWpog==

Required

Request Elements

In this request, you need to specify the lifecycle configuration in the request body using the elements described in Table 2. The configuration information will be uploaded in XML format.

If the versioning 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 it becomes a historical one (time when the version is replaced by a new version) and NoncurrentDays. For example, if NoncurrentDays is set to 1, a version will be deleted one day after it becomes the historical one. If V1 of object A is created on the first date of a month and new V2 is uploaded on the fifth date of the month, V1 becomes a historical version. At 00:00 on the seventh date of the month, V1 will expire. (Remarks: The deletion of an object may be delayed after the object has expired. Generally, the delay does not exceed 48 hours.)

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

  • The versioning of the bucket is enabled:
    • If the latest version of an object is not deletemarker, a new deletemarker is generated for the object.
    • If the latest version of an object is deletemarker and the object has this version only, the version will be deleted.
    • If the latest version of an object is deletemarker and the object has other versions, all versions of the object remain unchanged.
  • The versioning 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.
Table 2 Request elements for lifecycle configuration

Element

Description

Required or Optional

Date

Indicates when the specified rule takes effect.

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

Type: string

Ancestor: Expiration

Required if the Days element is absent.

Days

Indicates the number of days after object creation when the specified rule takes effect. (valid only for the latest object version)

Type: positive integer

Ancestor: Expiration

Required if the Date element is absent.

Expiration

Indicates the container for the object expiration rule. (valid only for the latest object version)

Type: XML

Children: Date or Days

Ancestor: Rule

Required

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 configuration message body cannot exceed 20 KB.

Type: XML

Children: Rule

Ancestor: none

Required

NoncurrentDays

Indicates the number of days an object is noncurrent before the specified rule takes effect. (valid only for historical versions)

Type: positive integer

Ancestor: NoncurrentVersionExpiration

Required if the NoncurrentVersionExpiration element 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. (valid only for historical versions)

Type: XML

Children: NoncurrentDays

Ancestor: Rule

Optional

Prefix

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

Type: string

Ancestor: Rule

Required

Rule

Indicates the container for a lifecycle rule.

Type: container

Ancestor: LifecycleConfiguration

Required

Status

Indicates whether the rule is enabled.

Type: string

Ancestor: Rule

Valid values: Enabled, Disabled

Required

Response Syntax

HTTP/1.1 status_code
Date: date
Content-Length: length

Response Headers

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

Response Elements

This response contains no element.

Error Responses

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

Registration