AWS::S3::Bucket Rule - AWS CloudFormation

AWS::S3::Bucket Rule

Specifies lifecycle rules for an Amazon S3 bucket. For more information, see Put Bucket Lifecycle Configuration in the Amazon S3 API Reference.

You must specify at least one of the following properties: AbortIncompleteMultipartUpload, ExpirationDate, ExpirationInDays, NoncurrentVersionExpirationInDays, NoncurrentVersionTransition, NoncurrentVersionTransitions, Transition, or Transitions.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

Properties

AbortIncompleteMultipartUpload

Specifies a lifecycle rule that stops incomplete multipart uploads to an Amazon S3 bucket.

Required: Conditional

Type: AbortIncompleteMultipartUpload

Update requires: No interruption

ExpirationDate

Indicates when objects are deleted from Amazon S3 and Amazon S3 Glacier. The date value must be in ISO 8601 format. The time is always midnight UTC. If you specify an expiration and transition time, you must use the same time unit for both properties (either in days or by date). The expiration time must also be later than the transition time.

Required: Conditional

Type: String

Pattern: ^([0-2]\d{3})-(0[0-9]|1[0-2])-([0-2]\d|3[01])T([01]\d|2[0-4]):([0-5]\d):([0-6]\d)((\.\d{3})?)Z$

Update requires: No interruption

ExpirationInDays

Indicates the number of days after creation when objects are deleted from Amazon S3 and Amazon S3 Glacier. If you specify an expiration and transition time, you must use the same time unit for both properties (either in days or by date). The expiration time must also be later than the transition time.

Required: Conditional

Type: Integer

Update requires: No interruption

ExpiredObjectDeleteMarker

Indicates whether Amazon S3 will remove a delete marker without any noncurrent versions. If set to true, the delete marker will be removed if there are no noncurrent versions. This cannot be specified with ExpirationInDays, ExpirationDate, or TagFilters.

Required: No

Type: Boolean

Update requires: No interruption

Id

Unique identifier for the rule. The value can't be longer than 255 characters.

Required: No

Type: String

Maximum: 255

Update requires: No interruption

NoncurrentVersionExpiration

Specifies when noncurrent object versions expire. Upon expiration, Amazon S3 permanently deletes the noncurrent object versions. You set this lifecycle configuration action on a bucket that has versioning enabled (or suspended) to request that Amazon S3 delete noncurrent object versions at a specific period in the object's lifetime.

Required: No

Type: NoncurrentVersionExpiration

Update requires: No interruption

NoncurrentVersionExpirationInDays

(Deprecated.) For buckets with versioning enabled (or suspended), specifies the time, in days, between when a new version of the object is uploaded to the bucket and when old versions of the object expire. When object versions expire, Amazon S3 permanently deletes them. If you specify a transition and expiration time, the expiration time must be later than the transition time.

Required: Conditional

Type: Integer

Update requires: No interruption

NoncurrentVersionTransition

(Deprecated.) For buckets with versioning enabled (or suspended), specifies when non-current objects transition to a specified storage class. If you specify a transition and expiration time, the expiration time must be later than the transition time. If you specify this property, don't specify the NoncurrentVersionTransitions property.

Required: Conditional

Type: NoncurrentVersionTransition

Update requires: No interruption

NoncurrentVersionTransitions

For buckets with versioning enabled (or suspended), one or more transition rules that specify when non-current objects transition to a specified storage class. If you specify a transition and expiration time, the expiration time must be later than the transition time. If you specify this property, don't specify the NoncurrentVersionTransition property.

Required: Conditional

Type: Array of NoncurrentVersionTransition

Update requires: No interruption

ObjectSizeGreaterThan

Specifies the minimum object size in bytes for this rule to apply to. Objects must be larger than this value in bytes. For more information about size based rules, see Lifecycle configuration using size-based rules in the Amazon S3 User Guide.

Required: No

Type: String

Pattern: [0-9]+

Maximum: 20

Update requires: No interruption

ObjectSizeLessThan

Specifies the maximum object size in bytes for this rule to apply to. Objects must be smaller than this value in bytes. For more information about sized based rules, see Lifecycle configuration using size-based rules in the Amazon S3 User Guide.

Required: No

Type: String

Pattern: [0-9]+

Maximum: 20

Update requires: No interruption

Prefix

Object key prefix that identifies one or more objects to which this rule applies.

Important

Replacement must be made for object keys containing special characters (such as carriage returns) when using XML requests. For more information, see XML related object key constraints.

Required: No

Type: String

Update requires: No interruption

Status

If Enabled, the rule is currently being applied. If Disabled, the rule is not currently being applied.

Required: Yes

Type: String

Allowed values: Enabled | Disabled

Update requires: No interruption

TagFilters

Tags to use to identify a subset of objects to which the lifecycle rule applies.

Required: No

Type: Array of TagFilter

Update requires: No interruption

Transition

(Deprecated.) Specifies when an object transitions to a specified storage class. If you specify an expiration and transition time, you must use the same time unit for both properties (either in days or by date). The expiration time must also be later than the transition time. If you specify this property, don't specify the Transitions property.

Required: Conditional

Type: Transition

Update requires: No interruption

Transitions

One or more transition rules that specify when an object transitions to a specified storage class. If you specify an expiration and transition time, you must use the same time unit for both properties (either in days or by date). The expiration time must also be later than the transition time. If you specify this property, don't specify the Transition property.

Required: Conditional

Type: Array of Transition

Update requires: No interruption

Examples

Manage the lifecycle for S3 objects

The following example template shows an S3 bucket with a lifecycle configuration rule. The rule applies to all objects with the glacier key prefix. The objects are transitioned to Glacier after one day, and deleted after one year.

JSON

{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "S3Bucket": { "Type": "AWS::S3::Bucket", "Properties": { "AccessControl": "Private", "LifecycleConfiguration": { "Rules": [ { "Id": "GlacierRule", "Prefix": "glacier", "Status": "Enabled", "ExpirationInDays": 365, "Transitions": [ { "TransitionInDays": 1, "StorageClass": "GLACIER" } ] } ] } } } }, "Outputs": { "BucketName": { "Value": { "Ref": "S3Bucket" }, "Description": "Name of the sample Amazon S3 bucket with a lifecycle configuration." } } }

YAML

AWSTemplateFormatVersion: 2010-09-09 Resources: S3Bucket: Type: 'AWS::S3::Bucket' Properties: AccessControl: Private LifecycleConfiguration: Rules: - Id: GlacierRule Prefix: glacier Status: Enabled ExpirationInDays: 365 Transitions: - TransitionInDays: 1 StorageClass: GLACIER Outputs: BucketName: Value: !Ref S3Bucket Description: Name of the sample Amazon S3 bucket with a lifecycle configuration.

See also