Lifecycle configuration elements - Amazon Simple Storage Service (original) (raw)

A S3 Lifecycle configuration consist of Lifecycle rules that include various elements that describe the actions Amazon S3 takes during and objects lifetime. You specify an Amazon S3 Lifecycle configuration as XML, consisting of one or more Lifecycle rules, where each rule consists of one or more elements.

<LifecycleConfiguration>
    <Rule>
         <Element>
    </Rule>
    <Rule>
         <Element>
         <Element>
    </Rule>
</LifecycleConfiguration>

Each rule consists of the following:

Topics

The following sections describe the XML elements in an S3 Lifecycle configuration. For example configurations, see Examples of S3 Lifecycle configurations.

ID element

An S3 Lifecycle configuration can have up to 1,000 rules. This limit is not adjustable. The <ID> element uniquely identifies a rule. ID length is limited to 255 characters.

Status element

The <Status> element value can be either Enabled orDisabled. If a rule is disabled, Amazon S3 doesn't perform any of the actions defined in the rule.

Filter element

A S3 Lifecycle rule can apply to all or a subset of objects in a bucket based on the<Filter> element that you specify in the rule.

You can filter objects by key prefix, object tags, or a combination of both (in which case Amazon S3 uses a logical AND to combine the filters). For examples and more information about filters see, Adding filters to Lifecycle rules.

<LifecycleConfiguration>  
    <Rule>  
        <Filter>  
           <Prefix>logs/</Prefix>  
        </Filter>  
        transition/expiration actions  
         ...  
    </Rule>  
    ...  
</LifecycleConfiguration>  

If you want to apply a lifecycle action to a subset of objects based on different key name prefixes, specify separate rules. In each rule, specify a prefix-based filter. For example, to describe a lifecycle action for objects with the key prefixes projectA/ and projectB/, you specify two rules as follows:

<LifecycleConfiguration>  
    <Rule>  
        <Filter>  
           <Prefix>projectA/</Prefix>  
        </Filter>  
        transition/expiration actions  
         ...  
    </Rule>  
    <Rule>  
        <Filter>  
           <Prefix>projectB/</Prefix>  
        </Filter>  
        transition/expiration actions  
         ...  
    </Rule>  
</LifecycleConfiguration>  

For more information about object keys, see Naming Amazon S3 objects.

<LifecycleConfiguration>  
    <Rule>  
        <Filter>  
           <Tag>  
              <Key>key</Key>  
              <Value>value</Value>  
           </Tag>  
        </Filter>  
        transition/expiration actions  
        ...  
    </Rule>  
</LifecycleConfiguration>  

You can specify a filter based on multiple tags. You must wrap the tags in the<And> element, as shown in the following example. The rule directs Amazon S3 to perform lifecycle actions on objects with two tags (with the specific tag key and value).

<LifecycleConfiguration>  
    <Rule>  
      <Filter>  
         <And>  
            <Tag>  
               <Key>key1</Key>  
               <Value>value1</Value>  
            </Tag>  
            <Tag>  
               <Key>key2</Key>  
               <Value>value2</Value>  
            </Tag>  
             ...  
          </And>  
      </Filter>  
      transition/expiration actions  
    </Rule>  
</Lifecycle>  

The Lifecycle rule applies to objects that have both of the tags specified. Amazon S3 performs a logical AND. Note the following:

Note

When you specify multiple tags in a filter, each tag key must be unique.

<LifecycleConfiguration>  
    <Rule>  
        <Filter>  
          <And>  
             <Prefix>key-prefix</Prefix>  
             <Tag>  
                <Key>key1</Key>  
                <Value>value1</Value>  
             </Tag>  
             <Tag>  
                <Key>key2</Key>  
                <Value>value2</Value>  
             </Tag>  
              ...  
          </And>  
        </Filter>  
        <Status>Enabled</Status>  
        transition/expiration actions  
    </Rule>  
</LifecycleConfiguration>  

Amazon S3 combines these filters by using a logical AND. That is, the rule applies to the subset of objects with the specified key prefix and the specified tags. A filter can have only one prefix, and zero or more tags.

<LifecycleConfiguration>  
    <Rule>  
        <Filter>  
        </Filter>  
        <Status>Enabled</Status>  
        transition/expiration actions  
    </Rule>  
</LifecycleConfiguration>  
                    <LifecycleConfiguration>  
    <Rule>  
        <Filter>  
            <ObjectSizeGreaterThan>500</ObjectSizeGreaterThan>  
        </Filter>  
        <Status>Enabled</Status>  
        transition/expiration actions  
    </Rule>  
</LifecycleConfiguration>  
Note

The ObjectSizeGreaterThan and ObjectSizeLessThan filters exclude the specified values. For example, if you set objects sized 128 KB to 1024 KB to move from the S3 Standard storage class to the S3 Standard-IA storage class, objects that are exactly 1024 KB and 128 KB won't transition to S3 Standard-IA. Instead, the rule will apply only to objects that are greater than 128 KB and less than 1024 KB in size.
If you're specifying an object size range, theObjectSizeGreaterThan integer must be less than theObjectSizeLessThan value. When using more than one filter, you must wrap the filters in an <And> element. The following example shows how to specify objects in a range between 500 bytes and 64,000 bytes.

<LifecycleConfiguration>  
    <Rule>  
        <Filter>  
            <And>  
                <Prefix>key-prefix</Prefix>  
                <ObjectSizeGreaterThan>500</ObjectSizeGreaterThan>  
                <ObjectSizeLessThan>64000</ObjectSizeLessThan>  
            </And>  
        </Filter>  
        <Status>Enabled</Status>  
        transition/expiration actions  
    </Rule>  
</LifecycleConfiguration>  

Elements to describe lifecycle actions

You can direct Amazon S3 to perform specific actions in an object's lifetime by specifying one or more of the following predefined actions in an S3 Lifecycle rule. The effect of these actions depends on the versioning state of your bucket.

In addition, Amazon S3 provides the following actions that you can use to manage noncurrent object versions in a versioned bucket (that is, versioning-enabled and versioning-suspended buckets).

Note

Object expiration lifecycle configurations don't remove incomplete multipart uploads. To remove incomplete multipart uploads, you must use theAbortIncompleteMultipartUpload Lifecycle configuration action that's described later in this section.

In addition to the transition and expiration actions, you can use the following Lifecycle configuration actions to direct Amazon S3 to stop incomplete multipart uploads or to remove expired object delete markers:

Note

You can't specify this lifecycle action in a rule that has a filter that uses object tags.

Note

You can't specify this lifecycle action in a rule that has a filter that uses object tags.

How Amazon S3 calculates how long an object has been noncurrent

In a versioning-enabled bucket, you can have multiple versions of an object. There is always one current version, and zero or more noncurrent versions. Each time you upload an object, the current version is retained as the noncurrent version and the newly added version, the successor, becomes the current version. To determine the number of days an object is noncurrent, Amazon S3 looks at when its successor was created. Amazon S3 uses the number of days since its successor was created as the number of days an object is noncurrent.

Restoring previous versions of an object when using S3 Lifecycle configurations

As explained in Restoring previous versions, you can use either of the following two methods to retrieve previous versions of an object:

When you're using S3 Lifecycle configuration rules with versioning-enabled buckets, we recommend as a best practice that you use Method 1.

S3 Lifecycle operates under an eventually consistent model. A current version that you permanently deleted might not disappear until the changes propagate to all of the Amazon S3 systems. (Therefore, Amazon S3 might be temporarily unaware of this deletion.) In the meantime, the lifecycle rule that you configured to expire noncurrent objects might permanently remove noncurrent objects, including the one that you want to restore. So, copying the old version, as recommended in Method 1, is the safer alternative.

Lifecycle actions and bucket versioning state

The following table summarizes the behavior of the S3 Lifecycle configuration rule actions on objects in relation to the versioning state of the bucket that contains the object.

Action Nonversioned bucket (versioning not enabled) Versioning-enabled bucket Versioning-suspended bucket
Transition When a specified date or time period in the object's lifetime is reached. Amazon S3 transitions the object to the specified storage class. Amazon S3 transitions the current version of the object to the specified storage class. Same behavior as a versioning-enabled bucket.
Expiration When a specified date or time period in the object's lifetime is reached. The Expiration action deletes the object, and the deleted object can't be recovered. If the current version isn't a delete marker, Amazon S3 creates a delete marker, which becomes the current version, and the existing current version is retained as a noncurrent version. The lifecycle action creates a delete marker withnull version ID, which becomes the current version. If the version ID of the current version of the object isnull, the Expiration action permanently deletes this version. Otherwise, the current version is retained as a noncurrent version.
NoncurrentVersionTransition For noncurrent versions in a versioning enabled or versioning suspended bucket, S3 Lifecycle transitions an object when the number of days since the object has been noncurrent exceeds both the value specified under Days after objects become noncurrent () in the rule and when the number of versions exceeds the value specified in Number of newer versions to retain () in the rule. NoncurrentVersionTransition has no effect. Amazon S3 transitions the noncurrent object versions to the specified storage class. Same behavior as a versioning-enabled bucket.
NoncurrentVersionExpiration For noncurrent versions in a versioning enabled or versioning suspended bucket, S3 Lifecycle expires an object when the number of days since the object has been noncurrent exceeds both the value specified under Days after objects become noncurrent () in the rule and when the number of versions exceeds the value specified in Number of newer versions to retain () in the rule. NoncurrentVersionExpiration has no effect. The NoncurrentVersionExpiration action permanently deletes the noncurrent version of the object, and the deleted object can't be recovered. Same behavior as a versioning-enabled bucket.

Lifecycle rules: Based on an object's age

You can specify a time period, in the number of days from the creation (or modification) of the object, when Amazon S3 can take the specified action.

When you specify the number of days in the Transition andExpiration actions in an S3 Lifecycle configuration, note the following:

Note

Amazon S3 maintains only the last modified date for each object. For example, the Amazon S3 console shows the Last modified date in the object'sProperties pane. When you initially create a new object, this date reflects the date that the object is created. If you replace the object, the date changes accordingly. Therefore, the creation date is synonymous with the Last modified date.

When specifying the number of days in the NoncurrentVersionTransition and NoncurrentVersionExpiration actions in a Lifecycle configuration, note the following:

Lifecycle rules: Based on a specific date

When specifying an action in an S3 Lifecycle rule, you can specify a date when you want Amazon S3 to take the action. When the specific date arrives, Amazon S3 applies the action to all qualified objects (based on the filter criteria).

If you specify an S3 Lifecycle action with a date that is in the past, all qualified objects become immediately eligible for that lifecycle action.

Important

The date-based action is not a one-time action. Amazon S3 continues to apply the date-based action even after the date has passed, as long as the rule status isEnabled.

For example, suppose that you specify a date-based Expiration action to delete all objects (assume that no filter is specified in the rule). On the specified date, Amazon S3 expires all the objects in the bucket. Amazon S3 also continues to expire any new objects that you create in the bucket. To stop the lifecycle action, you must either remove the action from the lifecycle rule, disable the rule, or delete the rule from the lifecycle configuration.

The date value must conform to the ISO 8601 format. The time is always midnight UTC.

Note

You can't create date-based Lifecycle rules by using the Amazon S3 console, but you can view, disable, or delete such rules.