tencent cloud

Cloud Object Storage

PUT Bucket lifecycle

Baixar
Modo Foco
Tamanho da Fonte
Última atualização: 2026-06-12 17:14:54

Feature Description

COS allows you to manage the lifecycle of objects in a Bucket by configuring lifecycle rules. A lifecycle configuration contains one or more rule sets that apply to a group of objects. Each rule defines an action for COS. These actions fall into the following two categories:
Transition: This rule defines when an object transitions to another storage class. For example, you can choose to transition an object to the STANDARD_IA storage class (suitable for infrequent access) 30 days after its creation. It also supports moving data to the INTELLIGENT_TIERING storage class (for variable access patterns) and the ARCHIVE storage class (lower cost). For specific parameters, see the Transition item in the request sample description.
Expiration: Specifies the expiration time of an object. COS automatically deletes expired objects.
Note:
If the Bucket already has a lifecycle configured, using this API to create a new configuration will overwrite the existing one.
The Days and Date parameters cannot be supported simultaneously within a single lifecycle rule. Please create two separate rules and pass them in individually. For details, see the practical example below.
Buckets with Multi-AZ configuration enabled do not support transitioning storage types from Multi-AZ to Single-AZ.
Each bucket can have a maximum of 1,000 lifecycle rules.
Lifecycle rules based on Access Time (Atime) are currently available via allowlist. They only support transitioning data to the STANDARD_IA storage class, are not compatible with MAZ buckets, and do not support Tag filtering or object size filtering. For more restrictions and details, see Lifecycle Rules Based on Access Time.


Authorization Description

In an authorization policy, set the action to cos:PutBucketLifecycle. View all actions.

Request

Request Example

PUT /?lifecycle HTTP/1.1
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com
Content-Length: length
Date: GMT Date
Authorization: Auth String
Content-MD5: MD5
Note:
Host: <BucketName-APPID>.cos.<Region>.myqcloud.com. Here, <BucketName-APPID> is the bucket name with the APPID suffix, for example, examplebucket-1250000000. For details, see the Bucket Overview > Basic Information and Bucket Overview > Bucket Naming Conventions documents. <Region> is the available region of COS. For details, see the Regions and Access Domains document.
Authorization: Auth String (For details, see Request Signature).

Request Header

This API only uses common request headers. For details, see Common Request Headers.

Request Body

The specific node content of the request body for this API is:
<LifecycleConfiguration>
<Rule>
<ID>String</ID>
<Filter>
<And>
<Prefix>String</Prefix>
<PrefixNotEquals>String</PrefixNotEquals>
<Tag>
<Key>String</Key>
<Value>String</Value>
</Tag>
<ObjectSizeGreaterThan>Integer</ObjectSizeGreaterThan>
<ObjectSizeLessThan>Integer</ObjectSizeLessThan>
</And>
</Filter>
<Status>String</Status>
<Transition>
<Days>Integer</Days>
<StorageClass>String</StorageClass>
</Transition>
<NoncurrentVersionExpiration>
<NoncurrentDays>Integer</NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
<Rule>
<ID>String</ID>
<Filter>
<Prefix>String</Prefix>
</Filter>
<Status>String</Status>
<Transition>
<Days>Integer</Days>
<StorageClass>String</StorageClass>
</Transition>
<NoncurrentVersionTransition>
<NoncurrentDays>Integer</NoncurrentDays>
<StorageClass>String</StorageClass>
</NoncurrentVersionTransition>
</Rule>
<Rule>
<ID>String</ID>
<Filter>
<Prefix>String</Prefix>
</Filter>
<Status>String</Status>
<Expiration>
<ExpiredObjectDeleteMarker>Boolean</ExpiredObjectDeleteMarker>
</Expiration>
<NoncurrentVersionExpiration>
<NoncurrentDays>Integer</NoncurrentDays>
</NoncurrentVersionExpiration>
<AbortIncompleteMultipartUpload>
<DaysAfterInitiation>Integer</DaysAfterInitiation>
</AbortIncompleteMultipartUpload>
</Rule>
<Rule>
<ID>String</ID>
<Filter>
<And>
<Prefix>String</Prefix>
<PrefixNotEquals>String</PrefixNotEquals>
</And>
</Filter>
<Status>String</Status>
<Transition>
<AccessFrequency>
<AccessCountLessThan>Container</AccessCountLessThan>
<RecentDays>Integer</RecentDays>
</AccessFrequency>
<StorageClass>String</StorageClass>
</Transition>
<NoncurrentVersionTransition>
<AccessFrequency>
<AccessCountLessThan>Container</AccessCountLessThan>
<RecentDays>Integer</RecentDays>
</AccessFrequency>
<StorageClass>String</StorageClass>
</NoncurrentVersionTransition>
</Rule>
</LifecycleConfiguration>

The specific content is as follows:
Node Name (Keyword)
Parent Node
Description
Type
Required
LifecycleConfiguration
None
Lifecycle configuration.
Container
Yes
Rule
LifecycleConfiguration
Rule Description
Container
Yes
ID
LifecycleConfiguration.Rule
Uniquely identifies a rule. The length cannot exceed 255 characters.
String
No
Filter
LifecycleConfiguration.Rule
Filter describes the object set affected by the rule.
Container
No
And
LifecycleConfiguration.Rule
.Filter
A subset of the object filter. This element is required only when multiple filtering rules need to be specified, for example: specifying both Prefix and Tag filters, or specifying multiple Tag filters simultaneously.
Container
No
Prefix
LifecycleConfiguration.Rule
.Filter.And
Specifies the prefix to which the rule applies. Objects matching the prefix are affected by this rule, supporting at most one prefix.
String
No
PrefixNotEquals
LifecycleConfiguration.Rule.Filter.And
Filters Objects whose Prefix does not match the specified string. Only one PrefixNotEquals is allowed, and its scope is a subset of Prefix.
String
No
ObjectSizeGreaterThan
LifecycleConfiguration.Rule .Filter.And
Filters objects whose size must be greater than a specified value (excluding equal), measured in Bytes.
Note:
The value of ObjectSizeGreaterThan must be greater than or equal to 65536.
If a rule's Filter contains a condition for filtering by object size, that rule cannot simultaneously include the AbortIncompleteMultipartUpload and ExpiredObjectDeleteMarker actions.
Integer
No
ObjectSizeLessThan
LifecycleConfiguration.Rule .Filter.And
Filters objects whose size must be less than a specified value (excluding equal), measured in Bytes.
Note:
The value of ObjectSizeLessThan must be greater than or equal to 65537.
The value of ObjectSizeLessThan must be greater than the value of ObjectSizeGreaterThan.
If a rule's Filter contains a condition for filtering by object size, that rule cannot simultaneously include the AbortIncompleteMultipartUpload and ExpiredObjectDeleteMarker actions.
Integer
No
Tag
LifecycleConfiguration.Rule
.Filter.And
A collection of Tags, supporting up to 10 Tags.
Container
No
Key
LifecycleConfiguration.Rule
.Filter.And.Tag
The Key of a Tag, with a length not exceeding 128 bytes, supporting English letters, numbers, spaces, plus signs, minus signs, underscores, equal signs, periods, colons, and slashes.
Minus signs, underscores, equal signs, periods, colons, and slashes.
String
No
Value
LifecycleConfiguration.Rule
.Filter.And.Tag
The Value of a Tag, with a length not exceeding 256 bytes, supporting English letters, numbers, spaces, plus signs, minus signs, underscores, equal signs, periods, colons, and slashes.
Minus signs, underscores, equal signs, periods, colons, and slashes.
String
No
Status
LifecycleConfiguration.Rule
Indicates whether the rule is enabled. Valid values: Enabled, Disabled.
String
Yes
Expiration
LifecycleConfiguration.Rule
The expiration attribute of a rule. You can configure it together with the Transition attribute (the rule transition attribute) or choose to configure only one of these attributes.
Container
No
ExpiredObjectDeleteMarker
LifecycleConfiguration.Rule
.Expiration
Deletes deletion markers that have no version history. Valid values: true, false.
true: indicates the deletion of deletion markers that have no version history.
false: indicates that deletion markers with no version history are not deleted.
Note:
Within a single rule, you cannot simultaneously configure the parameter for deleting the current version.
This parameter takes effect only when the NoncurrentVersionsExpiration rule is also configured within the same rule.
Boolean
No
Transition
LifecycleConfiguration.Rule
The transition attribute of a rule, describing when an object transitions to a different storage class and what the target storage class is. You can configure it together with the Expiration attribute (the rule expiration attribute) or choose to configure only one of these attributes.
Container
No
Days
LifecycleConfiguration.Rule
.Transition or .Expiration
Specifies the number of days after the object's last modification date when the action corresponding to the rule is performed.
For Transition, the valid value for this field is a non-negative integer. The maximum supported duration is 3650 days.
For Expiration, the valid value for this field is a positive integer, with a maximum supported duration of 3650 days.
Integer
No
AccessFrequency
Transition or NoncurrentVersionTransition
Specifies lifecycle rules based on access time. After this field is configured, fields related to last modification time (Days and NoncurrentDays) cannot be configured.
Note:
For lifecycle rules based on access time, see Lifecycle Rules Based on Access Time for details.
Container
No
RecentDays
AccessFrequency
Indicates the number of consecutive access days, which must not exceed 365. AccessCountLessThan must be configured together with this field, indicating that objects are transitioned when the number of accesses within the specified consecutive days is below a certain threshold. Fields related to last modification time (Days and NoncurrentDays) cannot be configured.
Integer
Yes
AccessCountLessThan
AccessFrequency
Indicates the number of times an object is accessed, with a default value of 1. RecentDays must be configured together with this field, indicating that objects are transitioned when the number of accesses within the specified consecutive days is below a certain threshold. Fields related to last modification time (Days and NoncurrentDays) cannot be configured.
Container
Yes
AbortIncompleteMultipartUpload
LifecycleConfiguration.Rule
Cleaning up incomplete multipart uploads and file fragments.
Container
No
DaysAfterInitiation
LifecycleConfiguration.Rule
.AbortIncompleteMultipartUpload
Specifies the number of days after a multipart upload is initiated within which it must be completed.
Integer
Yes
NoncurrentVersionExpiration
LifecycleConfiguration.Rule
Specifies when noncurrent version objects expire.
Container
No
NoncurrentVersionTransition
LifecycleConfiguration.Rule
Specifying when noncurrent version objects transition to a different storage class and what the target storage class is.
Container
No
NoncurrentDays
LifecycleConfiguration.Rule
.NoncurrentVersionExpiration
or NoncurrentVersionTransition
Specifies the number of days after an object becomes a noncurrent version when the action corresponding to the rule is performed.
For Transition, the valid value for this field is a non-negative integer. The maximum supported duration is 3650 days.
For Expiration, the valid value for this field is a positive integer, with a maximum supported duration of 3650 days.
Integer
No
StorageClass
LifecycleConfiguration.Rule
Transition or NoncurrentVersionTransition
Specifies the storage class for objects after transition. Enumeration values: STANDARD_IA, MAZ_STANDARD_IA, INTELLIGENT_TIERING, MAZ_INTELLIGENT_TIERING, ARCHIVE, DEEP_ARCHIVE. For details about storage classes, see Storage Class Overview.
String
Yes

Response

Response Headers

This API only returns common response headers. For details, see Common Response Headers.

Response Body

This response body is empty.

Error Codes

This API follows unified error responses and error codes. For details, see Error Codes.

Practical Case

Case 1: Archiving Objects Based on Last Modified Time

Request

PUT /?lifecycle HTTP/1.1
Host:examplebucket-1250000000.cos.ap-beijing.myqcloud.com
Date: Wed, 16 Aug 2017 11:59:33 GMT
Authorization:q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1502855771;1502935771&q-key-time=1502855771;1502935771&q-header-list=content-md5;host&q-url-param-list=lifecycle&q-signature=****************************************
Content-MD5: LcNUuow8OSZMrEDnvndw1Q==
Content-Length: 348
Content-Type: application/x-www-form-urlencoded

<LifecycleConfiguration>
<Rule>
<ID>id1</ID>
<Filter>
<Prefix>documents/</Prefix>
</Filter>
<Status>Enabled</Status>
<Transition>
<Days>100</Days>
<StorageClass>ARCHIVE</StorageClass>
</Transition>
</Rule>
<Rule>
<ID>id2</ID>
<Filter>
<Prefix>logs/</Prefix>
</Filter>
<Status>Enabled</Status>
<Transition>
<Days>10</Days>
<StorageClass>STANDARD_IA</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration>

Response

HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 Aug 2017 11:59:33 GMT
Server: tencent-cos
x-cos-request-id: NTk5NDMzYTRfMjQ4OGY3Xzc3NGRf****

Case 2: Archiving Objects Based on Access Time

Request

PUT /?lifecycle HTTP/1.1
Host:examplebucket-1250000000.cos.ap-beijing.myqcloud.com
Date: Wed, 16 Aug 2020 11:59:33 GMT
Authorization:q-sign-algorithm=sha1&q-ak=************************************&q-sign-time=1502855771;1502935771&q-key-time=1502855771;1502935771&q-header-list=content-md5;host&q-url-param-list=lifecycle&q-signature=****************************************
Content-MD5: LcNUuow8OSZMrEDnvndw1Q==
Content-Length: 348
Content-Type: application/x-www-form-urlencoded

<LifecycleConfiguration>
<Rule>
<ID>id1</ID>
<Filter>
<Prefix>documents/</Prefix>
</Filter>
<Status>Enabled</Status>
<Transition>
<AccessFrequency>
<AccessCountLessThan>2</AccessCountLessThan>
<RecentDays>7</RecentDays>
</AccessFrequency>
<StorageClass></StorageClass>
</Transition>
<NoncurrentVersionTransition>
<AccessFrequency>
<AccessCountLessThan>2</AccessCountLessThan>
<RecentDays>7</RecentDays>
</AccessFrequency>
<StorageClass></StorageClass>
</NoncurrentVersionTransition>
</Rule>
</LifecycleConfiguration>

Response

HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 Aug 2020 11:59:33 GMT
Server: tencent-cos
x-cos-request-id: NTk5NDMzYTRfMjQ4OGY3Xzc3NGRf****

Ajuda e Suporte

Esta página foi útil?

comentários