Applying lifecycle policies

To automatically delete objects after a set time period, you can use lifecycle policies. For more information about lifecycle policies, see the FAQ entry "What are lifecycle policies and how do I use them?".

The commands depend on the S3-compatible tool you're using. This getting started explains each step with example commands for the MinIO Client and the AWS CLI with a JSON file. For S3cmd, use an XML file and see the official S3cmd documentation.

  1. Create a lifecycle configuration, e.g. expiry.json:

    (see JSON Syntax)

    {
     "Rules": [{
        "ID": "expiry",
        "Status": "Enabled",
        "Prefix": "",
    
        "Expiration": {
          "Days": 90
        },
        "NoncurrentVersionExpiration": {
          "NoncurrentDays": 30
        },
        "AbortIncompleteMultipartUpload": {
          "DaysAfterInitiation": 10
        }
      },
      {
        "ID": "deletemarker",
        "Status": "Enabled",
        "Prefix": "",
    
        "Expiration": {
          "ExpiredObjectDeleteMarker": true
        }
      }]
    }

    The configuration above will perform the following deletions:

    Option Description
    Expiration: Days 90 days after an object was created, it is either permanently deleted (no versioning), or a delete marker is added (versioning enabled/suspended).
    NoncurrentVersionExpiration Note that our Object Storage only supports the option NoncurrentDays for this data type.

    30 days after an object became a "noncurrent version" (replaced by a newer version), it is permanently deleted — unless object lock is applied.
    AbortIncompleteMultipartUpload 10 days after a multipart upload was aborted, the "leftover" parts are automatically deleted.
    ExpiredObjectDeleteMarker If a delete marker is the only remaining version of an object and all noncurrent versions have been permanently deleted, the delete marker is also deleted.

 

  1. Apply the lifecycle configuration to your Bucket:

    • MinIO Client

      With the MinIO Client, you also have the option to set lifecycle rules directly without a JSON file.

      mc ilm rule import <alias_name>/<bucket_name> < expiry.json
    • AWS CLI

      aws s3api put-bucket-lifecycle-configuration --bucket <bucket_name> --lifecycle-configuration  file://expiry.json

 

  1. View the lifecycle rules:

    • MinIO Client

      mc ilm rule ls <alias_name>/<bucket_name>
    • AWS CLI

      aws s3api get-bucket-lifecycle-configuration --bucket <bucket_name>

 

  1. Remove the lifecycle rules:

    • MinIO Client

      mc ilm rule rm --id "expiry" <alias_name>/<bucket_name>
      mc ilm rule rm --all --force <alias_name>/<bucket_name>
    • AWS CLI

      Delete all rules:

      aws s3api delete-bucket-lifecycle --bucket <bucket_name>

      If you want to delete individual rules, you can save the current rules in lifecycle.json with the command below, edit the rules, and apply the new lifecycle configuration as explained in step 2.

      aws s3api get-bucket-lifecycle-configuration --bucket <bucket_name> --output json > lifecycle.json

As long as the lifecycle rules are applied, you're objects should get deleted automatically.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Versioning

To protect your objects from getting deleted by accident, you can use Versioning. For more...

Object Lock: Legal Hold

To protect your objects from getting deleted by accident, you can use the Object Lock options...

Object Lock: Retention

To protect your objects from getting deleted by accident, you can use the Object Lock options...

Applying CORS policies

To enable cross-origin requests to your Bucket, you can configure CORS policies. For more...

Encrypting data with SSE-C

You can use SSE-C ("Server-Side Encryption with Customer-provided keys") when you upload new...

Powered by WHMCompleteSolution