diff --git a/S3-API-FAQ.md b/S3-API-FAQ.md index 5a9d203..c1ca16e 100644 --- a/S3-API-FAQ.md +++ b/S3-API-FAQ.md @@ -52,3 +52,40 @@ rclone lsf seaweedfs:my-bucket/dir ``` If the directory `dir` exists in `my-bucket`, the orphaned metadata will be cleaned up. Note that due to slight API usage differences, `rclone ls` does not trigger cleanup, but `rclone lsf` will. + + +## Setting TTL + +It is possible to set a TTL for a specific directory using the S3 API. They are set using [`PutBucketLifecycleConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html). + +Example of a JSON configuration is below. It is an equivalent of calling the following with `weed shell`. +``` +fs.configure -locationPrefix /buckets/f341868e-baff-4e20-896a-08bc148e32f9/my-directory-whose-files-will-expire-in-20-days -ttl 20d -apply +``` +: + +``` +{ + "Rules": [ + { + "Status": "Enabled", + "Filter": { + "Prefix": "my-directory-whose-files-will-expire-in-20-days" + }, + "Expiration": { + "Days": 20d + } + } + ] +} +``` +Save that in a `.json` file and call it, for example, via the `aws` cli: + +``` +BUCKET_NAME=f341868e-baff-4e20-896a-08bc148e32f9 +aws --endpoint-url http://127.0.0.1:8333 s3api put-bucket-lifecycle-configuration --bucket $BUCKET_NAME --lifecycle-configuration "file://lifecycle_policy.json" +``` + +Note that you don't need to add the part `/buckets/$BUCKET_NAME` in the configurations "Filter.Prefix" (contrary to using `fs.configure`, this is taken care of for you in the S3 API. + +