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 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 condition under which the action will be taken.|
||Defines the action to be taken, which must contain one and only one specific action element. Required.|
||Action element to delete objects in the bucket.|
||Action element to change the storage class of an object.|
||Defines the condition under which the action will be taken, which must contain at least one specific condition element. Required.|
||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. "2013-01-15".|
||Condition element relevant only for versioned objects. Matches live
objects if the value is
||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> x-goog-project-id: <project id> <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: Thu, 12 Mar 2012 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