Configures lifecycle rules for a bucket. Use the PutBucketLifecycle operation to periodically convert object storage classes or delete expired objects and parts based on last modification time or last access time, reducing storage costs.
Notes
-
PutBucketLifecycle uses overwrite semantics. To add a new rule (Rule2) while keeping an existing rule (Rule1):
-
Call GetBucketLifecycle to query the existing Rule1 configuration.
-
Add Rule2 to the existing configuration.
-
Call PutBucketLifecycle with both Rule1 and Rule2 to update the bucket.
-
-
Lifecycle rules can expire objects and parts from incomplete multipart uploads.
-
Rules can be based on last access time or last modified time.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket Policy.
|
API |
Action |
Description |
|
PutBucketLifecycle |
oss:PutBucketLifecycle |
Configures lifecycle rules for a bucket. |
Request syntax
PUT /?lifecycle HTTP/1.1
Date: GMT Date
Content-Length: ContentLength
Content-Type: application/xml
Authorization: SignatureValue
Host: BucketName.oss.aliyuncs.com
<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
<Rule>
<ID>RuleID</ID>
<Prefix>Prefix</Prefix>
<Status>Status</Status>
<Expiration>
<Days>Days</Days>
</Expiration>
<Transition>
<Days>Days</Days>
<StorageClass>StorageClass</StorageClass>
</Transition>
<AbortMultipartUpload>
<Days>Days</Days>
</AbortMultipartUpload>
</Rule>
</LifecycleConfiguration>
Request headers
|
Header |
Type |
Required |
Example |
Description |
|
x-oss-allow-same-action-overlap |
String |
No |
true |
Specifies whether to allow overlapped prefixes. Valid values:
|
This request also uses common headers such as Date and Authorization, described in Common HTTP headers.
Request elements
|
Element |
Type |
Required |
Example |
Description |
|
LifecycleConfiguration |
Container |
Yes |
N/A |
The container for lifecycle configurations. Supports up to 1,000 lifecycle rules. Child nodes: Rule Parent nodes: none |
|
Rule |
Container |
Yes |
N/A |
The container for a lifecycle rule. The expiration-to-deletion period must exceed the expiration-to-storage-class-conversion period for IA or Archive. Child nodes: ID, Prefix, Status, and Expiration Parent nodes: LifecycleConfiguration |
|
ID |
String |
No |
rule1 |
The lifecycle rule ID. Maximum length: 255 characters. If unspecified, OSS generates a unique ID automatically. Child nodes: none Parent nodes: Rule |
|
Prefix |
String |
No |
tmp/ |
The object name prefix to which this rule applies. Prefixes across rules cannot overlap.
Child nodes: none Parent nodes: Rule |
|
Status |
String |
Yes |
Enabled |
Specifies whether to enable the rule. Valid values:
Parent nodes: Rule |
|
Expiration |
Container |
No |
N/A |
The delete operation to perform on matching objects when they expire. In versioned buckets, this applies only to current versions. The expiration-to-deletion period must exceed the expiration-to-storage-class-conversion period for IA or Archive. Child nodes: Days, CreatedBeforeDate, or ExpiredObjectDeleteMarker Parent nodes: Rule |
|
Days |
Positive integer |
Either Days or CreatedBeforeDate is required |
1 |
The number of days after the last modification date before the rule takes effect. If IsAccessTime is true, the rule takes effect based on days after last access instead. Parent nodes: Expiration or AbortMultipartUpload |
|
CreatedBeforeDate |
String |
Either Days or CreatedBeforeDate is required |
2002-10-11T00:00:00.000Z |
The date before which the rule applies. OSS performs the operation on objects last modified before this date. Format: yyyy-MM-ddT00:00:00.000Z. Time must be 00:00:00 UTC in ISO 8601 format. Parent nodes: Expiration or AbortMultipartUpload |
|
ExpiredObjectDeleteMarker |
String |
No |
true |
Specifies whether to automatically remove expired delete markers. Valid values:
Parent nodes: Expiration |
|
Transition |
Container |
No |
N/A |
The storage class conversion for matching objects when they expire. Standard objects can transition to IA, Archive, or Cold Archive. The transition-to-Archive period must exceed the transition-to-IA period. For example, if objects transition to IA after 30 days, they must transition to Archive after more than 30 days. Parent nodes: Rule Child nodes: Days, CreatedBeforeDate, and StorageClass Important
Important
Either Days or CreatedBeforeDate is required. |
|
StorageClass |
String |
Yes if Transition or NoncurrentVersionTransition is specified |
IA |
The storage class to which objects are changed. Valid values:
Important
You can convert the storage class of objects in an IA bucket to only Archive or Cold Archive. Parent nodes: Transition |
|
AbortMultipartUpload |
Container |
No |
N/A |
The operation to delete parts from incomplete multipart uploads when they expire. Child nodes: Days or CreatedBeforeDate Parent nodes: Rule |
|
Tag |
Container |
No |
N/A |
The tag of objects to which the lifecycle rule applies. You can specify multiple tags. Parent nodes: Rule Child nodes: Key and Value |
|
Key |
String |
Yes if the Tag element is specified |
TagKey1 |
The key of the tag that is specified for the objects. Parent nodes: Tag |
|
Value |
String |
Yes if the Tag element is specified |
TagValue1 |
The value of the tag that is specified for the objects. Parent nodes: Tag |
|
NoncurrentVersionExpiration |
Container |
No |
N/A |
The operation to delete previous versions of matching objects when they expire. Child nodes: NoncurrentDays |
|
NoncurrentVersionTransition |
Container |
No |
N/A |
The storage class conversion for previous versions of matching objects when they expire. Previous versions can transition to IA or Archive. The transition-to-Archive period must exceed the transition-to-IA period for previous versions. Child nodes: NoncurrentDays and StorageClass |
|
NoncurrentDays |
String |
Yes if NoncurrentVersionExpiration or NoncurrentVersionTransition is specified |
10 |
The number of days after objects become previous versions before the rule takes effect. If IsAccessTime is true, NoncurrentDays takes effect based on days after last access instead. Parent nodes: NoncurrentVersionTransition and NoncurrentVersionExpiration |
|
IsAccessTime |
String |
No |
true |
Specifies whether the lifecycle rule applies to objects based on their last access time. Valid values:
Parent nodes: Transition or NoncurrentVersionTransition |
|
ReturnToStdWhenVisit |
String |
No |
false |
Specifies whether to convert non-Standard objects back to Standard upon access. Takes effect only when IsAccessTime is true. Valid values:
Parent nodes: Transition or NoncurrentVersionTransition |
|
AllowSmallFile |
String |
No |
false |
Specifies whether to convert objects smaller than 64 KB to IA, Archive, or Cold Archive based on last access time. Valid values:
Parent nodes: Transition or NoncurrentVersionTransition |
|
Filter |
Container |
No |
N/A |
The container for the Not element used to filter objects. Supports at most one Not node. Parent nodes: Rule Child nodes: Not |
|
Not |
Container |
No |
N/A |
The exclusion condition for the lifecycle rule. Only one Not node is allowed per Filter. Parent nodes: Filter Child nodes: Prefix and Tag |
|
Prefix |
String |
Yes |
tmp/not/ |
The object name prefix excluded from the lifecycle rule. Cannot be empty.
Parent nodes: Not Child nodes: none |
|
Tag |
Container |
No |
N/A |
The tag of excluded objects. Supports at most one tag. |
|
ObjectSizeGreaterThan |
Positive integer |
No |
500 |
The minimum object size to which this rule applies. You can specify only one value or leave this element empty. If both this parameter and the ObjectSizeLessThan parameter are set, the system will verify that the object size falls within the specified range-greater than the minimum size and less than the maximum size. This parameter and the AllowSmallFile parameter are mutually exclusive. Parent node: Filter Child node: none |
|
ObjectSizeLessThan |
Positive integer |
No |
64000 |
The minimum object size to which this rule applies. You can specify only one value or leave this element empty. If both this parameter and the ObjectSizeGreaterThan parameter are set, the system will verify that the object size falls within the specified range-greater than the minimum size and less than the maximum size. This parameter and the AllowSmallFile parameter are mutually exclusive. Parent node: Filter Child node: none |
Response headers
The response contains only common response headers. For more information, see Common response headers.
Examples
Sample requests
Example 1: Configure a lifecycle rule based on the last modified time to only convert the storage class of objects
Example 2: Configure a lifecycle rule based on the last modified time to only delete objects
Example 3: Configure a lifecycle rule based on the last modified time to convert the storage class of objects and delete objects
Example 4: Configure a lifecycle rule based on the last modified time to delete previous versions of objects and remove delete markers
Example 5: Configure a lifecycle rule based on the last modified time to convert the storage class of objects and delete objects, excluding objects whose names contain specific prefixes or objects that have specific tags
Example 6: Configure a lifecycle rule based on the last access time to convert the storage class of objects
Example 7: Configure a lifecycle rule based on the last modified time to delete parts
Example 8: Configure a lifecycle rule based on the last modified time to delete objects whose names contain overlapping prefixes
Sample responses
HTTP/1.1 200 OK
x-oss-request-id: 7D3435J59A9812BAD56E
Date: Mon, 6 May 2019 15:23:20 GMT
Content-Length: 0
Connection: keep-alive
Server: AliyunOSS
OSS SDKs
Call PutBucketLifecycle using the following OSS SDKs:
ossutil
For information about the ossutil command that corresponds to the PutBucketLifecycle operation, see put-bucket-lifecycle.
Reference
For more information about lifecycle rules, see Lifecycle.
Error codes
|
Error code |
HTTP status code |
Description |
|
InvalidArgument |
400 |
Possible causes:
|
|
AccessDenied |
403 |
You lack the |
|
MalforedXML |
400 |
The MalformedXML error is returned when lifecycle rule XML validation fails. For example, configuring a rule based on last access time without enabling access tracking triggers this error. |