

# Creating and managing a lifecycle configuration for your Amazon S3 on Outposts bucket
<a name="S3OutpostsLifecycleManaging"></a>

You can use S3 Lifecycle to optimize storage capacity for Amazon S3 on Outposts. You can create lifecycle rules to expire objects as they age or are replaced by newer versions. You can create, enable, disable, or delete a lifecycle rule.

For more information about S3 Lifecycle, see [Creating and managing a lifecycle configuration for your Amazon S3 on Outposts bucket](#S3OutpostsLifecycleManaging).

**Note**  
The AWS account that creates the bucket owns it and is the only one that can create, enable, disable, or delete a lifecycle rule.

To create and manage the lifecycle configuration for your S3 on Outposts bucket, see the following topics.

**Topics**
+ [

# Creating and managing a lifecycle rule by using the AWS Management Console
](S3OutpostsLifecycleConsole.md)
+ [

# Creating and managing a lifecycle configuration by using the AWS CLI and SDK for Java
](S3OutpostsLifecycleCLIJava.md)

# Creating and managing a lifecycle rule by using the AWS Management Console
<a name="S3OutpostsLifecycleConsole"></a>

You can use S3 Lifecycle to optimize storage capacity for Amazon S3 on Outposts. You can create lifecycle rules to expire objects as they age or are replaced by newer versions. You can create, enable, disable, or delete a lifecycle rule.

For more information about S3 Lifecycle, see [Creating and managing a lifecycle configuration for your Amazon S3 on Outposts bucket](S3OutpostsLifecycleManaging.md).

**Note**  
The AWS account that creates the bucket owns it and is the only one that can create, enable, disable, or delete a lifecycle rule.

To create and manage a lifecycle rule for an S3 on Outposts by using the AWS Management Console, see the following topics.

**Topics**
+ [

## Creating a lifecycle rule
](#s3-outposts-bucket-create-lifecycle)
+ [

## Enabling a lifecycle rule
](#s3-outposts-bucket-enable-lifecycle)
+ [

## Editing a lifecycle rule
](#s3-outposts-bucket-edit-lifecycle)
+ [

## Deleting a lifecycle rule
](#s3-outposts-bucket-delete-lifecycle)

## Creating a lifecycle rule
<a name="s3-outposts-bucket-create-lifecycle"></a>

1. Sign in to the AWS Management Console and open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the left navigation pane, choose **Outposts buckets**.

1. Choose the Outposts bucket that you want to create a lifecycle rule for.

1. Choose the **Management** tab, and then choose **Create Lifecycle rule**.

1. Enter a value for **Lifecycle rule name**.

1. Under **Rule scope**, choose one of the following options:
   + To limit the scope to specific filters, choose **Limit the scope of this rule using one or more filters**. Then, add a prefix filter, tags, or object size.
   + To apply the rule to all objects in the bucket, choose **Apply to all objects in the bucket**.

1. Under **Lifecycle rule actions**, choose one of the following options:
   + **Expire current versions of objects** – For versioning-enabled buckets, S3 on Outposts adds a delete marker and retains the objects as noncurrent versions. For buckets that don't use S3 Versioning, S3 on Outposts permanently deletes the objects.
   + **Permanently delete noncurrent versions of objects ** – S3 on Outposts permanently deletes noncurrent versions of objects. 
   + **Delete expired object delete markers or incomplete multipart uploads** – S3 on Outposts permanently deletes expired object delete markers or incomplete multipart uploads.

     If you limit the scope of your Lifecycle rule by using object tags, you can't choose **Delete expired object delete markers**. You also can't choose **Delete expired object delete markers** if you choose **Expire current object versions**.
**Note**  
Size-based filters can't be used with delete markers and incomplete multipart uploads.

1. If you chose **Expire current versions of objects** or **Permanently delete noncurrent versions of objects**, configure the rule trigger based on a specific date or the object's age. 

1. If you chose **Delete expired object delete markers**, to confirm that you want to delete expired object delete markers, select **Delete expired object delete markers**.

1. Under **Timeline Summary**, review your Lifecycle rule, and choose **Create rule**.

## Enabling a lifecycle rule
<a name="s3-outposts-bucket-enable-lifecycle"></a>

**To enable or disable a bucket lifecycle rule**

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the left navigation pane, choose **Outposts buckets**.

1. Choose the Outposts bucket that you want to enable or disable a lifecycle rule for.

1. Choose the **Management** tab, and then under **Lifecycle rule**, choose the rule that you want to enable or disable.

1. For **Action**, choose **Enable or disable rule**.

## Editing a lifecycle rule
<a name="s3-outposts-bucket-edit-lifecycle"></a>

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the left navigation pane, choose **Outposts buckets**.

1. Choose the Outposts bucket that you want to edit a lifecycle rule for.

1. Choose the **Management** tab, and then choose the **Lifecycle rule** that you want to edit.

1. (Optional) Update the value for **Lifecycle rule name**.

1. Under **Rule scope**, edit the scope as needed:
   + To limit the scope to specific filters, choose **Limit the scope of this rule using one or more filters**. Then, add a prefix filter, tags, or object size.
   + To apply the rule to all objects in the bucket, choose **Apply to all objects in the bucket**.

1. Under **Lifecycle rule actions**, choose one of the following options:
   + **Expire current versions of objects** – For versioning-enabled buckets, S3 on Outposts adds a delete marker and retains the objects as noncurrent versions. For buckets that don't use S3 Versioning, S3 on Outposts permanently deletes the objects.
   + **Permanently delete noncurrent versions of objects ** – S3 on Outposts permanently deletes noncurrent versions of objects. 
   + **Delete expired object delete markers or incomplete multipart uploads** – S3 on Outposts permanently deletes expired object delete markers or incomplete multipart uploads.

     If you limit the scope of your Lifecycle rule by using object tags, you can't choose **Delete expired object delete markers**. You also can't choose **Delete expired object delete markers** if you choose **Expire current object versions**.
**Note**  
Size-based filters can't be used with delete markers and incomplete multipart uploads.

1. If you chose **Expire current versions of objects** or **Permanently delete noncurrent versions of objects**, configure the rule trigger based on a specific date or the object age. 

1. If you chose **Delete expired object delete markers**, to confirm that you want to delete expired object delete markers, select **Delete expired object delete markers**.

1. Choose **Save**.

## Deleting a lifecycle rule
<a name="s3-outposts-bucket-delete-lifecycle"></a>

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. In the left navigation pane, choose **Outposts buckets**.

1. Choose the Outposts bucket that you want to delete a lifecycle rule for.

1. Choose the **Management** tab, and then under **Lifecycle rule**, choose the rule that you want to delete.

1. Choose **Delete**.

# Creating and managing a lifecycle configuration by using the AWS CLI and SDK for Java
<a name="S3OutpostsLifecycleCLIJava"></a>

You can use S3 Lifecycle to optimize storage capacity for Amazon S3 on Outposts. You can create lifecycle rules to expire objects as they age or are replaced by newer versions. You can create, enable, disable, or delete a lifecycle rule.

For more information about S3 Lifecycle, see [Creating and managing a lifecycle configuration for your Amazon S3 on Outposts bucket](S3OutpostsLifecycleManaging.md).

**Note**  
The AWS account that creates the bucket owns it and is the only one that can create, enable, disable, or delete a lifecycle rule.

To create and manage a lifecycle configuration for an S3 on Outposts bucket by using the AWS Command Line Interface (AWS CLI) and the AWS SDK for Java, see the following examples.

**Topics**
+ [

## PUT a lifecycle configuration
](#S3OutpostsPutBucketLifecycleConfiguration)
+ [

## GET the lifecycle configuration on an S3 on Outposts bucket
](#S3OutpostsGetBucketLifecycleConfiguration)

## PUT a lifecycle configuration
<a name="S3OutpostsPutBucketLifecycleConfiguration"></a>

------
#### [ AWS CLI ]

The following AWS CLI example puts a lifecycle configuration policy on an Outposts bucket. This policy specifies that all objects that have the flagged prefix (`myprefix`) and tags expire after 10 days. To use this example, replace each `user input placeholder` with your own information.

1. Save the lifecycle configuration policy to a JSON file. In this example, the file is named `lifecycle1.json`.

   ```
   {
       "Rules": [
           {
               "ID": "id-1",
               "Filter": {
                   "And": {
                       "Prefix": "myprefix", 
                       "Tags": [
                           {
                               "Value": "mytagvalue1", 
                               "Key": "mytagkey1"
                           }, 
                           {
                               "Value": "mytagvalue2", 
                               "Key": "mytagkey2"
                           }
                       ],
                       "ObjectSizeGreaterThan": 1000,
                       "ObjectSizeLessThan": 5000
                   }
               }, 
               "Status": "Enabled", 
               "Expiration": {
                   "Days": 10
               }
           }
       ]
   }
   ```

1. Submit the JSON file as part of the `put-bucket-lifecycle-configuration` CLI command. To use this command, replace each `user input placeholder` with your own information. For more information about this command, see [put-bucket-lifecycle-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3control/put-bucket-lifecycle-configuration.html) in the *AWS CLI Reference*.

   ```
   aws s3control put-bucket-lifecycle-configuration --account-id 123456789012 --bucket arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/bucket/example-outposts-bucket --lifecycle-configuration file://lifecycle1.json
   ```

------
#### [ SDK for Java ]

The following SDK for Java example puts a lifecycle configuration on an Outposts bucket. This lifecycle configuration specifies that all objects that have the flagged prefix (`myprefix`) and tags expire after 10 days. To use this example, replace each `user input placeholder` with your own information. For more information, see [PutBucketLifecycleConfiguration](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_PutBucketLifecycleConfiguration.html) in the *Amazon Simple Storage Service API Reference*.

```
import com.amazonaws.services.s3control.model.*;

public void putBucketLifecycleConfiguration(String bucketArn) {

    S3Tag tag1 = new S3Tag().withKey("mytagkey1").withValue("mytagkey1");
    S3Tag tag2 = new S3Tag().withKey("mytagkey2").withValue("mytagkey2");

    LifecycleRuleFilter lifecycleRuleFilter = new LifecycleRuleFilter()
            .withAnd(new LifecycleRuleAndOperator()
                    .withPrefix("myprefix")
                    .withTags(tag1, tag2))
                    .withObjectSizeGreaterThan(1000)
                    .withObjectSizeLessThan(5000);

    LifecycleExpiration lifecycleExpiration = new LifecycleExpiration()
            .withExpiredObjectDeleteMarker(false)
            .withDays(10);

    LifecycleRule lifecycleRule = new LifecycleRule()
            .withStatus("Enabled")
            .withFilter(lifecycleRuleFilter)
            .withExpiration(lifecycleExpiration)
            .withID("id-1");

    LifecycleConfiguration lifecycleConfiguration = new LifecycleConfiguration()
            .withRules(lifecycleRule);

    PutBucketLifecycleConfigurationRequest reqPutBucketLifecycle = new PutBucketLifecycleConfigurationRequest()
            .withAccountId(AccountId)
            .withBucket(bucketArn)
            .withLifecycleConfiguration(lifecycleConfiguration);

    PutBucketLifecycleConfigurationResult respPutBucketLifecycle = s3ControlClient.putBucketLifecycleConfiguration(reqPutBucketLifecycle);
    System.out.printf("PutBucketLifecycleConfiguration Response: %s%n", respPutBucketLifecycle.toString());

}
```

------

## GET the lifecycle configuration on an S3 on Outposts bucket
<a name="S3OutpostsGetBucketLifecycleConfiguration"></a>

------
#### [ AWS CLI ]

The following AWS CLI example gets a lifecycle configuration on an Outposts bucket. To use this command, replace each `user input placeholder` with your own information. For more information about this command, see [get-bucket-lifecycle-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3control/get-bucket-lifecycle-configuration.html) in the *AWS CLI Reference*.

```
aws s3control get-bucket-lifecycle-configuration --account-id 123456789012 --bucket arn:aws:s3-outposts:<your-region>:123456789012:outpost/op-01ac5d28a6a232904/bucket/example-outposts-bucket
```

------
#### [ SDK for Java ]

The following SDK for Java example gets a lifecycle configuration for an Outposts bucket. For more information, see [GetBucketLifecycleConfiguration](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_GetBucketLifecycleConfiguration.html) in the *Amazon Simple Storage Service API Reference*.

```
import com.amazonaws.services.s3control.model.*;

public void getBucketLifecycleConfiguration(String bucketArn) {

    GetBucketLifecycleConfigurationRequest reqGetBucketLifecycle = new GetBucketLifecycleConfigurationRequest()
            .withAccountId(AccountId)
            .withBucket(bucketArn);

    GetBucketLifecycleConfigurationResult respGetBucketLifecycle = s3ControlClient.getBucketLifecycleConfiguration(reqGetBucketLifecycle);
    System.out.printf("GetBucketLifecycleConfiguration Response: %s%n", respGetBucketLifecycle.toString());

}
```

------