Description
COS allows you to manage the lifecycle of objects in buckets through lifecycle configuration, which contains one or more rulesets that will be applied to a set of object rules (where each rule defines an operation in COS).
These operations include the following two types:
- Conversion: Defines the time when an object is converted to another storage type. For example, you can convert an object to the infrequent access storage (STANDARD_IA, suitable for infrequent access) 30 days after creation. The data can also be stored in the archive storage (ARCHIVE, lower costs and available in China). For specific parameters, see the Transition item in the sample request description.
- Expiration: Specifies the expiration time of an object. COS automatically deletes expired objects.
Notes
PUT Bucket lifecycle is used to create a new lifecycle configuration for a Bucket. If a lifecycle configuration has already been set for the bucket, the new configuration created with this API will overwrite the existing one.
Request
Request Example
PUT /?lifecycle HTTP/1.1
Host: <BucketName-APPID>.<Endpoint>
Content-Length: length
Date: GMT Date
Authorization: Auth String
Content-MD5: MD5
Note:
Authorization: Auth String (See Request Signature for details.)
Request Header
Common Headers
This request uses common request headers. For details, see Public Request Headers.
Non-common Headers
Required headers:
This request is implemented by using the following required headers.
| Name | Description | Type | Required |
|---|---|---|---|
| Content-MD5 | Base64-encoded 128-bit content MD5 checksum as defined in RFC 1864. This header is used to verify whether the file content has changed. | String | Yes |
Request Body
The specific node content of the API request body is:
<LifecycleConfiguration>
<Rule>
<ID></ID>
<Filter>
<Prefix></Prefix>
</Filter>
<Status></Status>
<Transition>
<Days></Days>
<StorageClass></StorageClass>
</Transition>
<NoncurrentVersionExpiration>
<NoncurrentDays></NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
<Rule>
<ID></ID>
<Filter>
<Prefix></Prefix>
</Filter>
<Status></Status>
<Transition>
<Days></Days>
<StorageClass></StorageClass>
</Transition>
<NoncurrentVersionTransition>
<NoncurrentDays></NoncurrentDays>
<StorageClass></StorageClass>
</NoncurrentVersionTransition>
</Rule>
<Rule>
<ID></ID>
<Filter>
<Prefix></Prefix>
</Filter>
<Status></Status>
<Expiration>
<ExpiredObjectDeleteMarker></ExpiredObjectDeleteMarker>
</Expiration>
<NoncurrentVersionExpiration>
<NoncurrentDays></NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
</LifecycleConfiguration>
The specific contents are described as follows:
| Node Name (Keyword) | Parent Node | Description | Type | Required |
|---|---|---|---|---|
| LifecycleConfiguration | No | Lifecycle configuration | Container | Yes |
| Rule | LifecycleConfiguration | Rule description | Container | Yes |
| Filter | LifecycleConfiguration.Rule | Identifies objects that a lifecycle rule applies to. | Container | Yes |
| Status | LifecycleConfiguration.Rule | Indicates whether the rule is enabled. Enumerated values: Enabled, Disabled | Container | Yes |
| ID | LifecycleConfiguration.Rule | A unique identifier for the rule. It can be up to 255 characters. | String | No |
| And | LifecycleConfiguration.Rule.Filter | Used to combine Prefix | Container | No |
| Prefix | LifecycleConfiguration.Rule.Filter or LifecycleConfiguration.Rule.Filter.And |
Matching prefix for the rule. It specifies objects that the lifecycle rule applies to. There can be one Prefix at most. | Container | No |
| Expiration | LifecycleConfiguration.Rule | Expiration attributes of the rule | Container | No |
| Transition | LifecycleConfiguration.Rule | Transition attributes of the rule. Specifies when to transition the object to Standard_IA or Archive | Container | No |
| Days | LifecycleConfiguration.Rule.Transition or Expiration |
Specifies the number of days between the date an object was last modified and the date when the operation corresponding to the rule is performed. If it is a Transition operation, this value should be a non-negative integer. If it is an Expiration operation, this value should be a positive integer. The maximum value is 3650 (days). | Integer | No |
| Date | LifecycleConfiguration.Rule.Transition or Expiration |
Specifies when the operation corresponding to the rule is performed. | String | No |
| ExpiredObjectDeleteMarker | LifecycleConfiguration.Rule.Expiration | Indicates whether the delete marker of an expired object will be removed. Enumerated values: true, false | String | No |
| AbortIncompleteMultipartUpload | LifecycleConfiguration.Rule | Specifies the maximum time before a multipart upload is aborted. | Container | No |
| DaysAfterInitiation | LifecycleConfiguration.Rule.AbortIncompleteMultipartUpload | Specifies the number of days within which the multipart upload must be completed after it starts. | Integer | Yes |
| NoncurrentVersionExpiration | LifecycleConfiguration.Rule | Specifies when noncurrent object versions shall expire. | Container | No |
| NoncurrentVersionTransition | LifecycleConfiguration.Rule | Specifies when to transition objects of noncurrent versions to STANDARD_IA or ARCHIVE. | Container | No |
| NoncurrentDays | LifecycleConfiguration.Rule.NoncurrentVersionExpiration or NoncurrentVersionTransition |
Specifies the number of days between the date when an object becomes noncurrent and the date when the operation corresponding to a rule is performed. If it is a Transition operation, this value should be a non-negative integer. If it is an Expiration operation, this value should be a positive integer. The maximum value is 3650 (days). | Integer | No |
| StorageClass | LifecycleConfiguration.Rule.Transition or NoncurrentVersionTransition |
Specifies the storage class of the transitioned object. Enumerated values: STANDARD_IA, ARCHIVE | String | Yes |
Response
Response Headers
Common Response Headers
This response uses common response headers. For details, see Common Response Headers.
Special Response Headers
There are no special response headers for this response operation.
Response Body
The response body is empty.
Error Code
The following table describes some special and common errors that may occur with this request. For detailed error causes, check the returned message. For details on error codes related to COS or the complete list of errors for the product, see Error Codes.
| Error Code | HTTP Status Code | Description |
|---|---|---|
| NoSuchBucket | 404 Not Found | The bucket does not exist. |
| MalformedXML | 400 Bad Request | The XML syntax of the request body is incorrect. Please compare it carefully with the restful API document. |
| InvalidRequest | 400 Bad Request | The request is illegal. If Conflict lifecycle rule is displayed in the error description, it means that multiple rules in the XML data have conflicting parts. |
| InvalidArgument | 400 Bad Request | The request parameter is illegal. If the error description shows Rule ID must be unique. Found same ID for more than one rule, it means that multiple rules have the same ID field. |
Practical Case
Request
PUT /?lifecycle HTTP/1.1
Host:<BucketName-APPID>.<Endpoint>
Date: Wed, 16 Aug 2017 11:59:33 GMT
Authorization:q-sign-algorithm=sha1&q-ak=AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&q-sign-time=1502855771;1502935771&q-key-time=1502855771;1502935771&q-header-list=content-md5;host&q-url-param-list=lifecycle&q-signature=f3aa2c708cfd8d4d36d658de56973c9cf1c24654
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>
<Expiration>
<Days>10</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
Response
HTTP/1.1 200 OK
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 Aug 2017 11:59:33 GMT
x-cos-request-id: NTk5NDMzYTRfMjQ4OGY3Xzc3NGRfMWY=