How to Set Lifecycle Policies Using the AWS CLI

In Wasabi, implementing lifecycle polices can be a great way to manage the lifespan of your data stored within your buckets.  Users on Wasabi may choose to implement lifecycle rules for compliance, internal policy, or for general housekeeping reasons. 


The AWS CLI provides the s3api put-bucket-lifecycle-configuration command that users can use to set or update the lifecycle configuration of their buckets.  The command requires the lifecycle policy defined for the bucket as JSON file or in string format. Instructions on how to set the lifecycle policy via the AWS CLI are outlined below:

1. Install and configure AWS CLI:

Ensure you have the AWS CLI installed and configured. You may refer to our KB article: How do I use the AWS CLI with Wasabi for instructions on how to set it up.


2. Define the lifecycle to apply to the bucket (see example policy below) in JSON format:



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. Please note that the ID has a 255 characters 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 e.g. 2024-04-18T00:00:00Z).

In short, the policy example above will automatically delete both current and non-current versions of objects in the bucket it is applied to. 


3. Run the following command:

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


Output: If successful, there is no visible output 


4. Verify Bucket Lifecycle Configuration

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


Output Sample:

Please note, in this example, we are applying the policy to a bucket in the us-east-1 region, hence the endpoint URL: You may refer to our support KB article: What are the service URLs for Wasabi's different storage regions? for a list of all available service endpoints/regions.



5. Verify from Wasabi Management Console


Have more questions? Submit a request