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
||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|
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.
||Defines the lifecycle management policies for the bucket, which contains
0 or more (up to 100) rules. Use an empty element (for example,
||Defines a lifecycle management rule, which is made of an action and the conditions that must be met for the action to occur.|
||Defines the action to occur. Must contain one and only one action element.|
||Action element to delete objects in the bucket.|
||Action element to change the storage class of objects in the bucket.|
||Conditions that must be met for the action to occur. A rule must contain at least one condition element.|
||Condition element that matches objects over the specified age (in days).|
||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".|
||Condition element typically only used in conjunction with
object versioning. When set
||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.|
||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.|
PUT /?lifecycle HTTP/1.1 Host: <bucket>.storage.googleapis.com Date: <date and time of the request> Content-Length: <request body length> Content-Type: <MIME type of the body> Authorization: <authentication string> <xml_document_defining_lifecycle_configuration>
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.
The following sample enables lifecycle management for a bucket named example.com. For more examples, see the Managing Lifecycles page.
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>
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