---
title: "Setting Lifecycle Policies Using the AWS CLI"
slug: "how-to-set-lifecycle-policies-using-the-aws-cli"
updated: 2026-01-07T15:50:14Z
published: 2026-01-07T15:50:14Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wasabi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Setting Lifecycle Policies Using the AWS CLI

Lifecycle policies can be a good way to manage the lifespan of your data stored within your buckets. You can implement lifecycle rules for compliance, internal policy, or general housekeeping. Lifecycle policies can be managed in the [Console](https://docs.wasabi.com/docs/lifecycle), using API requests with an application such as [Postman](https://docs.wasabi.com/docs/how-to-set-lifecycle-policies-using-postman), or with AWS CLI commands (as described in this article).

The AWS CLI provides the `s3api put-bucket-lifecycle-configuration` command to set or update the lifecycle configuration of your buckets. The command requires the lifecycle policy defined for the bucket as a JSON file or in string format. To set the lifecycle policy using the AWS CLI:

1. Install and configure AWS CLI. Refer to [AWS CLI with Wasabi](https://docs.wasabi.com/docs/how-do-i-use-aws-cli-with-wasabi) for instructions on setting it up.
2. Define the lifecycle to apply to the bucket in JSON format. For example:

```plaintext
{
                "Rules":[
                {
                "ID":"myExampleLifecylePolicyWithUniqueName",
                "Filter":{

                },
                "Status":"Enabled",
                "NoncurrentVersionExpiration":{
                "NoncurrentDays":90
                },
                "Expiration":{
                "Days":365
                }
                }
                ]
                }
```

The example policy configuration above sets a lifecycle rule for a bucket that applies to all objects within the bucket (both current and non-current versions). The rule defines an ID, which is a unique identifier for the lifecycle rule. Note that the ID has a 255-character limit.

The Status field activates or deactivates the rule and, in the policy example above, applies the rule to all objects within the bucket.

The Expiration action defines when objects in a bucket should be deleted. This field can be set in terms of Days or Date in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ such as *2024-04-18T00:00:00Z*).

In summary, the policy example above will automatically delete both current and non-current versions of objects in the bucket to which it is applied.
3. Run the following command:

```plaintext
aws s3api put-bucket-lifecycle-configuration --bucket {yourBucketNamesGoesHere} --lifecycle-configuration file://{pathToYourLifecylePolicy.json file} --endpoint-url=https://s3.{region}.wasabisys.com
```

If successful, there is no visible output.

![](https://cdn.document360.io/bef0a1ea-7768-4d5a-b520-c4fe2f7fafad/Images/Documentation/14727690966683.png)
4. Verify the bucket lifecycle configuration.

```plaintext
aws s3api get-bucket-lifecycle-configuration --bucket {yourBucketNamesGoesHere} --endpoint-url=https://s3.{region}.wasabisys.com
```

In this example, the policy is applied to a bucket in the us-east-1 region, hence the endpoint URL: [https://s3.wasabisys.com](https://s3.wasabisys.com). Refer to [Service URLs for Wasabi's Storage Regions](https://docs.wasabi.com/docs/service-urls-for-wasabis-storage-regions-2) for a list of all available service endpoints/regions.

![](https://cdn.document360.io/bef0a1ea-7768-4d5a-b520-c4fe2f7fafad/Images/Documentation/14727686439067.png)
5. Verify in the Wasabi Management Console.

**![](https://cdn.document360.io/bef0a1ea-7768-4d5a-b520-c4fe2f7fafad/Images/Documentation/14727822376219.png)**
