Amazon Simple Storage Service
API Reference (API Version 2006-03-01)

PutBucketLifecycleConfiguration

Creates a new lifecycle configuration for the bucket or replaces an existing lifecycle configuration. For information about lifecycle configuration, see Managing Access Permissions to Your Amazon S3 Resources.

Note

Bucket lifecycle configuration now supports specifying a lifecycle rule using an object key name prefix, one or more object tags, or a combination of both. Accordingly, this section describes the latest API. The previous version of the API supported filtering based only on an object key name prefix, which is supported for backward compatibility. For the related API description, see PutBucketLifecycle.

Rules

You specify the lifecycle configuration in your request body. The lifecycle configuration is specified as XML consisting of one or more rules. Each rule consists of the following:

  • Filter identifying a subset of objects to which the rule applies. The filter can be based on a key name prefix, object tags, or a combination of both.

  • Status whether the rule is in effect.

  • One or more lifecycle transition and expiration actions that you want Amazon S3 to perform on the objects identified by the filter. If the state of your bucket is versioning-enabled or versioning-suspended, you can have many versions of the same object (one current version and zero or more noncurrent versions). Amazon S3 provides predefined actions that you can specify for current and noncurrent object versions.

For more information, see Object Lifecycle Management and Lifecycle Configuration Elements.

Permissions

By default, all Amazon S3 resources are private, including buckets, objects, and related subresources (for example, lifecycle configuration and website configuration). Only the resource owner (that is, the AWS account that created it) can access the resource. The resource owner can optionally grant access permissions to others by writing an access policy. For this operation, a user must get the s3:PutLifecycleConfiguration permission.

You can also explicitly deny permissions. Explicit deny also supersedes any other permissions. If you want to block users or accounts from removing or deleting objects from your bucket, you must deny them permissions for the following actions:

  • s3:DeleteObject

  • s3:DeleteObjectVersion

  • s3:PutLifecycleConfiguration

For more information about permissions, see Managing Access Permissions to Your Amazon S3 Resources.

The following are related to PutBucketLifecycleConfiguration:

Request Syntax

PUT /?lifecycle HTTP/1.1 Host: Bucket.s3.amazonaws.com <?xml version="1.0" encoding="UTF-8"?> <LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Rule> <AbortIncompleteMultipartUpload> <DaysAfterInitiation>integer</DaysAfterInitiation> </AbortIncompleteMultipartUpload> <Expiration> <Date>timestamp</Date> <Days>integer</Days> <ExpiredObjectDeleteMarker>boolean</ExpiredObjectDeleteMarker> </Expiration> <Filter> <And> <Prefix>string</Prefix> <Tag> <Key>string</Key> <Value>string</Value> </Tag> ... </And> <Prefix>string</Prefix> <Tag> <Key>string</Key> <Value>string</Value> </Tag> </Filter> <ID>string</ID> <NoncurrentVersionExpiration> <NoncurrentDays>integer</NoncurrentDays> </NoncurrentVersionExpiration> <NoncurrentVersionTransition> <NoncurrentDays>integer</NoncurrentDays> <StorageClass>string</StorageClass> </NoncurrentVersionTransition> ... <Prefix>string</Prefix> <Status>string</Status> <Transition> <Date>timestamp</Date> <Days>integer</Days> <StorageClass>string</StorageClass> </Transition> ... </Rule> ... </LifecycleConfiguration>

URI Request Parameters

The request requires the following URI parameters.

Bucket

The name of the bucket for which to set the configuration.

Request Body

The request accepts the following data in XML format.

LifecycleConfiguration

Root level tag for the LifecycleConfiguration parameters.

Required: Yes

Rule

A lifecycle rule for individual objects in an Amazon S3 bucket.

Type: Array of LifecycleRule data types

Required: Yes

Response Syntax

HTTP/1.1 200

Response Elements

If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.

Examples

Example 1: Add lifecycle configuration - bucket not versioning-enabled

The following lifecycle configuration specifies two rules, each with one action.

  • The Transition action requests Amazon S3 to transition objects with the "documents/" prefix to the GLACIER storage class 30 days after creation.

  • The Expiration action requests Amazon S3 to delete objects with the "logs/" prefix 365 days after creation.

<LifecycleConfiguration> <Rule> <ID>id1</ID> <Filter> <Prefix>documents/</Prefix> </Filter> <Status>Enabled</Status> <Transition> <Days>30</Days> <StorageClass>GLACIER</StorageClass> </Transition> </Rule> <Rule> <ID>id2</ID> <Filter> <Prefix>logs/</Prefix> </Filter> <Status>Enabled</Status> <Expiration> <Days>365</Days> </Expiration> </Rule> </LifecycleConfiguration>

The following is a sample PUT /?lifecycle request that adds the preceding lifecycle configuration to the examplebucket bucket.

PUT /?lifecycle HTTP/1.1 Host: examplebucket.s3.amazonaws.com x-amz-date: Wed, 14 May 2014 02:11:21 GMT Content-MD5: q6yJDlIkcBaGGfb3QLY69A== Authorization: authorization string Content-Length: 415 <LifecycleConfiguration> <Rule> <ID>id1</ID> <Filter> <Prefix>documents/</Prefix> </Filter> <Status>Enabled</Status> <Transition> <Days>30</Days> <StorageClass>GLACIER</StorageClass> </Transition> </Rule> <Rule> <ID>id2</ID> <Filter> <Prefix>logs/</Prefix> </Filter> <Status>Enabled</Status> <Expiration> <Days>365</Days> </Expiration> </Rule> </LifecycleConfiguration>

Sample Response

HTTP/1.1 200 OK x-amz-id-2: r+qR7+nhXtJDDIJ0JJYcd+1j5nM/rUFiiiZ/fNbDOsd3JUE8NWMLNHXmvPfwMpdc x-amz-request-id: 9E26D08072A8EF9E Date: Wed, 14 May 2014 02:11:22 GMT Content-Length: 0 Server: AmazonS3

Example 2: Add lifecycle configuration - bucket is versioning-enabled

The following lifecycle configuration specifies two rules, each with one action for Amazon S3 to perform. You specify these actions when your bucket is versioning-enabled or versioning is suspended:

  • The NoncurrentVersionExpiration action requests Amazon S3 to expire noncurrent versions of objects with the "logs/" prefix 100 days after the objects become noncurrent.

  • The NoncurrentVersionTransition action requests Amazon S3 to transition noncurrent versions of objects with the "documents/" prefix to the GLACIER storage class 30 days after they become noncurrent.

<LifeCycleConfiguration> <Rule> <ID>DeleteAfterBecomingNonCurrent</ID> <Filter> <Prefix>logs/</Prefix> </Filter> <Status>Enabled</Status> <NoncurrentVersionExpiration> <NoncurrentDays>100</NoncurrentDays> </NoncurrentVersionExpiration> </Rule> <Rule> <ID>TransitionAfterBecomingNonCurrent</ID> <Filter> <Prefix>documents/</Prefix> </Filter> <Status>Enabled</Status> <NoncurrentVersionTransition> <NoncurrentDays>30</NoncurrentDays> <StorageClass>GLACIER</StorageClass> </NoncurrentVersionTransition> </Rule> </LifeCycleConfiguration>

The following is a sample PUT /?lifecycle request that adds the preceding lifecycle configuration to the examplebucket bucket.

PUT /?lifecycle HTTP/1.1 Host: examplebucket.s3.amazonaws.com x-amz-date: Wed, 14 May 2014 02:21:48 GMT Content-MD5: 96rxH9mDqVNKkaZDddgnw== Authorization: authorization string Content-Length: 598 <LifeCycleConfiguration> <Rule> <ID>DeleteAfterBecomingNonCurrent</ID> <Filter> <Prefix>logs/</Prefix> </Filter> <Status>Enabled</Status> <NoncurrentVersionExpiration> <NoncurrentDays>1</NoncurrentDays> </NoncurrentVersionExpiration> </Rule> <Rule> <ID>TransitionSoonAfterBecomingNonCurrent</ID> <Filter> <Prefix>documents/</Prefix> </Filter> <Status>Enabled</Status> <NoncurrentVersionTransition> <NoncurrentDays>0</NoncurrentDays> <StorageClass>GLACIER</StorageClass> </NoncurrentVersionTransition> </Rule> </LifeCycleConfiguration>

Sample Response

HTTP/1.1 200 OK x-amz-id-2: aXQ+KbIrmMmoO//3bMdDTw/CnjArwje+J49Hf+j44yRb/VmbIkgIO5A+PT98Cp/6k07hf+LD2mY= x-amz-request-id: 02D7EC4C10381EB1 Date: Wed, 14 May 2014 02:21:50 GMT Content-Length: 0 Server: AmazonS3

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: