By default, buckets do not have lifecycle management enabled. To set or
modify lifecycle configuration for an existing bucket you make a PUT request
that is scoped to the bucket and you use the lifecycle
query string
parameter. You must include an XML document in the request body that contains
the lifecycle configuration. Notice that you cannot set lifecycle configuration
on a new bucket that you are creating.
You must have FULL_CONTROL
permission to set or modify lifecycle
configuration for an existing bucket. Also, you must be authenticated to use the
PUT Bucket method.
Query string parameters
Parameter | Description | Required |
---|---|---|
lifecycle |
You use this to add or change the lifecycle configuration on an existing bucket. You must provide the LifecycleConfiguration document in the request body. | No |
See signed URL query string parameters for information on the parameters you include when creating and using signed URLs.
Request headers
Request body elements
The following request body elements are applicable only if you use the
lifecycle
query string parameter to specify the lifecycle
configuration for an existing bucket.
Element | Description |
---|---|
LifecycleConfiguration |
Defines the lifecycle management policies for the bucket, which contains
0 or more (up to 100) rules. Use an empty element (for example,
<LifecycleConfiguration/> ) to disable lifecycle
management for the bucket. |
Rule |
Defines a lifecycle management rule, which is made of an action and the conditions that must be met for the action to occur. |
Action |
Defines the action to occur. Must contain one and only one action element. |
Delete |
Action element to delete objects in the bucket. |
SetStorageClass |
Action element to change the storage class of objects in the bucket. |
Condition |
Conditions that must be met for the action to occur. A rule must contain at least one condition element. |
Age |
Condition element that matches objects over the specified age (in days). |
CreatedBefore |
Condition element that matches objects created before midnight of the
specified date in UTC. The value is an ISO date string without a time zone,
e.g. 2019-01-15 . |
CustomTimeBefore |
Condition element that matches objects whose
Custom-Time
metadata contains a date that's older than the date set by this
condition. CustomTimeBefore is an ISO date string without a
time zone, e.g. 2020-02-25 . |
DaysSinceCustomTime |
Condition element that matches objects whose
Custom-Time
metadata is more than DaysSinceCustomTime days old. |
DaysSinceNoncurrentTime |
Condition element relevant only for versioned objects. Matches objects that have been noncurrent for more than the specified number of days. |
IsLive |
Condition element typically only used in conjunction with
object versioning. When set
to false , this condition is satisfied for any noncurrent
version of an object. When set to true , this condition is
satisfied for the live version of an object. If you don't use object
versioning, all your objects are considered live and match when
IsLive is true .
|
MatchesStorageClass |
Condition element that matches objects of the specified storage class. This condition can be added multiple times to the same rule in order to cover more than one storage class. |
NoncurrentTimeBefore |
Condition element relevant only for versioned objects. Matches objects
that became noncurrent on a
date prior to the date specified in this condition.
NoncurrentTimeBefore is an ISO date string without a
time zone, e.g. 2020-02-25 . |
NumberOfNewerVersions |
Condition element relevant only for versioned objects. If the value is N, the condition is satisfied when there are at least N versions (including the live version) newer than this version of the object. |
Request syntax
PUT /?lifecycle HTTP/1.1 Host: BUCKET_NAME.storage.googleapis.com Date: DATE Content-Length: REQUEST_BODY_LENGTH Content-Type: MIME_TYPE_OF_THE_BODY Authorization: AUTHENTICATION_STRING XML_DOCUMENT_DEFINING_LIFECYCLE_CONFIGURATION
Response headers
The request can return a variety of response headers depending on the request headers you use.
Response body elements
The response does not include an XML document in the response body.
Example
The following sample enables lifecycle management for a bucket named example.com. For more examples, see the Managing Lifecycles page.
Request
PUT /example.com?lifecycle HTTP/1.1 Host: storage.googleapis.com Content-Length: 220 Authorization: Bearer ya29.AHES6ZRVmB7fkLtd1XTmq6mo0S1wqZZi3-Lh_s-6Uw7p8vtgSwg <?xml version="1.0" ?> <LifecycleConfiguration> <Rule> <Action> <Delete/> </Action> <Condition> <Age>30</Age> </Condition> </Rule> </LifecycleConfiguration>
Response
HTTP/1.1 200 OK Date: Mon, 07 Jan 2019 03:38:42 GMT Expires: Mon, 01 Jan 1990 00:00:00 GMT Cache-Control: no-cache, no-store, must-revalidate Content-Length: 0 Content-Type: text/html