Put Bucket Lifecycle

最近更新时间:2020-07-13 21:55:09

Put Bucket Lifecyle


Description

This PUT interface will set a Bucket lifecyle rule. If a Bucket has a lifecycle rule before it, the newly added rule will completely overwrite the old one. Please note this to avoid deletion by mistake.
After the user sets the rules, KS3 will automatically delete or change the storage type of the matched object according to the user's settings.
If you want to use this interface, you need to be the owner of this Bucket.

Request

Grammar

PUT /?lifecycle HTTP/1.1
Host: {BucketName}.{endpoint}
Date: {date}
Authorization: {SignatureValue}
Content-length: {length}
Content-MD5: {md5}

Lifecycle configuration in the request body

Note:

Request parameters

The interface does not use request parameters.

Request header

In addition to the public header, this interface must have one of the following:

Name Description Necessity
Content-MD5 The 128 bit MD5 digest of data in body is encoded with Base64. This header must exist in order to check whether the body is damaged.For details RFC-1864
Type: String
Default: None
YES

Request Body

An XML describing the lifecyle configuration.

<LifecycleConfiguration>
  <Rule>
    <ID>id1</ID>
    <Filter>
      <Prefix>documents/</Prefix>
    </Filter>
    <Expiration>
      <Date>2016-12-31T00:00:00.000Z</Date>
    </Expiration>
    <Status>Enabled</Status>
  </Rule>
  <Rule>
    <ID>id2</ID>
    <Filter>
      <Prefix>logs/</Prefix>
    </Filter>
    <Expiration>
      <Days>130</Days>
    </Expiration>
    <Transition>
      <Days>10</Days>
      <StorageClass>STANDARD_IA</StorageClass>
    </Transition>
    <Transition>
      <Days>40</Days>
      <StorageClass>ARCHIVE</StorageClass>
    </Transition>
    <Status>Enabled</Status>
  </Rule>
  <Rule>
    <ID>id3</ID>
    <Filter>
      <Prefix>pic</Prefix>
    </Filter>
    <Status>Enabled</Status>
    <Expiration>
      <Date>2018-01-01T00:00:00.000Z</Date>
    </Expiration>
  </Rule>
</LifecycleConfiguration>

The rules mainly include:

  • Filter:The specified prefix, object key is the prefix, the object is applicable to this rule. If the prefix of log is specified, the object key starts with log1,log2,log/2016 will be deleted.
  • Status:Specify whether this rule is enabled or disabled.
  • Expiration:Description of the expiration of an object. It expires before a certain time, or after how many days.
  • Transition:Description of object conversion storage type.
    Note:
    • The execution time of the rule is 0 o'clock every day.
    • Total number of one Bukcet rule < = 100
    • The ID of a Rule must be unique in a bucket, but it can be the same in different buckets. The ID can be any string, including Chinese, but cannot exceed 255 characters (utf8 encoding).
    • There can be multiple rules in a bucket. Each rule has a different prefix, such as logs and docs. However, the prefixes of different rules cannot conflict, such as logs and logs2016.
    • Days specifies the relative time, which is the last modification time of the relative object. For example, the object is modified at 15:05 on January 2, 2017, and days is 2. The deletion occurs at 00:00 on January 5, 2017, that is, two days are postponed to the next 0 point.
      Note that the object last modify time mentioned here is the last PUT,POST,COPY time.
    • Date specifies the absolute time. It must be in the format of ISO 8601 such as 2017-01-01t00:00:00 + 08:00. Beijing time, time, minute and second must be written as 0 point. If it is not 0 point, an error will be reported. The rule will execute at 0:00 on the day specified by Date, and delete the object with last modify time < = the Date; if the Date is the past time, the rule will execute in the night of the day, and judge whether the last modify time is < = the Date when it is executed; if it is the future time, the rule will be executed only when it reaches the Date, and still judge whether the last modify time is < = the Date when it is executed.
    • StorageClass refers to the storage type of file conversion. The values include: standard_ia, archive refers to the storage type of file conversion. The values include: STANDARD_IA,ARCHIVE
      The nodes in XML are as follows:
Name Description Necessity
LifecycleConfiguration A container that contains a bunch of Rules. A bucket can contain up to 100 Rules.
Type: Container
Child nodes: Rule
Parent node: None
YES
Rule Include a rule.
Type: Container
Parent node: LifecycleConfiguration
YES
ID Unique ID of rule. ID in a bucket cannot be duplicate. The length of ID is less than or equal to 255 characters. Note that it is utf8 encoded character, not byte.
Type: String
Parent node: Rule
YES
Filter The Prefix is specified. A Rule can only have one Filter. The prefixes of different Rules cannot conflict.
Type: Container
Child nodes: Prefix
Parent node: Rule
NO
Prefix Objects matching this prefix will be deleted. A Rule can only have one Filter and one Prefix.
Type: String
Parent node: Filter
NO
Status In Enabled state, the rule is executed on a regular basis; in Disabled state, the rule is ignored, but the rule can be enabled instead of deleted at any time.
Type: String
Parent node: Rule
Value: Enabled, Disabled
YES
Expiration Specifies when the corresponding object is deleted.
Type: Container

Child nodes: Days,Date
Parent node: Rule
YES
Date Last modify day. Objects whose last modify day is less than this number are deleted. Must be Beijing time in ISO 8601 format. Time, minute and second must be filled with 0, that is, it must be 0 point.
Type: String
Parent node: Expiration,Transition
YES(If there's no days)
Days Specify a positive number, corresponding to how many days after last modify the object is deleted.
Type: integer
Parent node: Expiration,Transition
Yes (if there is no date)
Transition Specifies when the Object will be converted to IA or Archive storage type in the valid life cycle.
Type: Container
Child nodes: Days,Date,StorageClass
NO
StorageClass Specifies that the object is converted to the target storage type.
Parent node: Transition
Value: STANDARD_IA,ARCHIVE(The console uses aws sdk and does not support ARCHIVE)
No (must be included if transition has one)


Note:

  • ID must have, ID of different Rule cannot be duplicate.
  • Date and days can only be one of the two, and can't be left unchecked.
  • The status node must have one.
  • Expiration must have one.
  • Filter and Prefix can not exist. But if there is prefix, different rules cannot conflict. For example, log and log2016 are conflicting.
  • In the child nodes of rule, all that should appear can only appear once. For example, ID can only have one; Status can only have one.

Response header

This interface only has common response headers. For more information, please click Public response headers.

Response content

This interface does not return the corresponding content.

Special errors

This interface does not return any special errors.

Example

Request example

PUT /?lifecycle HTTP/1.1
Host: ks3-example.kss.ksyun.com
Date: Wed, 14 May 2014 02:11:21 GMT
Content-MD5: xxx 
Authorization: authorization string
Content-Length: yyy
Content-type: application/xml

<LifecycleConfiguration>
  <Rule>
    <ID>id1</ID>
    <Filter>
      <Prefix>documents/</Prefix>
    </Filter>
    <Expiration>
      <Date>2016-12-31T00:00:00+08:00</Date>
    </Expiration>
    <Status>Enabled</Status>
  </Rule>
 <Rule>
    <ID>id2</ID>
    <Filter>
      <Prefix>logs/</Prefix>
    </Filter>
    <Expiration>
      <Days>130</Days>
    </Expiration>
    <Transition>
      <Days>10</Days>
<StorageClass>STANDARD_IA</StorageClass>
    </Transition>
    <Transition>
      <Days>40</Days>
  <StorageClass>ARCHIVE</StorageClass>
    </Transition>
    <Status>Enabled</Status>
  </Rule>
  <Rule>
    <ID>id3</ID>
    <Filter>
      <Prefix>pic</Prefix>
    </Filter>
    <Status>Enabled</Status>
    <Expiration>
      <Date>2018-01-01T00:00:00.000Z</Date>
    </Expiration>
  </Rule>
</LifecycleConfiguration>


The above content is to set 2 rules in a bucket. Article 1 delete the object key starting with documents before December 31, 2016. Second, let the object key starting with logs be deleted 3 days after lastmodify. The third is the future time, which will be implemented on January 1, 2018. The implementation effect is to delete lastmodify < 2018-01-01.

Response example

HTTP/1.1 200 OK
Content-Length: 0
Date: Tue, 19 Jul 2017 09:14:23 GMT
Server: Tengine
x-kss-request-id: 54a47bda18ac4e6e91de369add54218e
x-kss-request-id: 54a47bda18ac4e6e91de369add54218e

金山云,开启您的云计算之旅

免费注册