⚠️ Object Storage is currently in Beta test. For more information see this FAQ: Object Storage » Beta test
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.
-
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 } }] }
-
Apply the lifecycle configuration to your Bucket:
-
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 s3api put-bucket-lifecycle-configuration --bucket <bucket_name> --lifecycle-configuration file://expiry.json
-
-
View the lifecycle rules:
-
mc ilm rule ls <alias_name>/<bucket_name>
-
aws s3api get-bucket-lifecycle-configuration --bucket <bucket_name>
-
-
Remove the lifecycle rules:
-
mc ilm rule rm --id "expiry" <alias_name>/<bucket_name> mc ilm rule rm --all --force <alias_name>/<bucket_name>
-
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
-
You're objects should now get deleted automatically.
Next: