You can create an S3 lifecycle configuration to control when specific objects are deleted from the StorageGRID system.
The simple example in this section illustrates how an S3 lifecycle configuration can control when certain objects are deleted (expired) from specific S3 buckets. The example in this section is for illustration purposes only. For complete details on creating S3 lifecycle configurations, see the section on object lifecycle management in the Amazon Simple Storage Service Developer Guide. Note that StorageGRID only supports Expiration actions; it does not support Transition actions.
Amazon Simple Storage Service Developer Guide: Object lifecycle management
A lifecycle configuration is a set of rules that are applied to the objects in specific S3 buckets. Each rule specifies which objects are affected and when those objects will expire (on a specific date or after some number of days).
If you apply a lifecycle configuration to a bucket, the lifecycle settings for the bucket always override StorageGRID ILM settings. StorageGRID uses the Expiration settings for the bucket, not ILM, to determine whether to delete or retain specific objects.
As a result, an object might be removed from the grid even though the placement instructions in an ILM rule still apply to the object. Or, an object might be retained on the grid even after any ILM placement instructions for the object have lapsed. For details, see How ILM operates throughout an object's life
in the instructions for performing StorageGRID administration.
{ "Rules": [ { "ID": "rule1", "Filter": { "And": { "Prefix": "category1/", "Tags": [ { "Key": "key2", "Value": "tag2" } ] } }, "Expiration": { "Date": "2020-08-22T00:00:00Z" }, "Status": "Enabled" }, { "ID": "rule2", "Filter": { "Prefix": "category2/" }, "Expiration": { "Days": 100 }, "Status": "Enabled" }, { "ID": "rule3", "Filter": { "Prefix": "category3/" }, "NoncurrentVersionExpiration": { "NoncurrentDays": 50 }, "Status": "Enabled" } ] }
After you have created the lifecycle configuration file, you apply it to a bucket by issuing a PUT Bucket lifecycle request.
This request applies the lifecycle configuration in the example file to objects in a bucket named testbucket:
aws s3api --endpoint-url <StorageGRID endpoint> put-bucket-lifecycle-configuration --bucket testbucket --lifecycle-configuration file://bktjson.json
To validate that a lifecycle configuration was successfully applied to the bucket, issue a GET Bucket lifecycle request. For example:
aws s3api --endpoint-url <StorageGRID endpoint> get-bucket-lifecycle-configuration --bucket testbucket\
A successful response lists the lifecycle configuration you just applied.
You can determine if an expiration rule in the lifecycle configuration applies to a specific object when issuing a PUT Object, HEAD Object, or GET Object request. If a rule applies, the response includes an Expiration parameter that indicates when the object expires and which expiration rule was matched.
How object retention is determinedin the instructions for performing StorageGRID administration.
For example, this PUT Object request was issued on 22 Jun 2020 and places an object in the testbucket bucket.
aws s3api --endpoint-url <StorageGRID endpoint> put-object --bucket testbucket --key obj2test2 --body bktjson.json
The success response indicates that the object will expire in 100 days (01 Oct 2020) and that it matched Rule 2 of the lifecycle configuration .
{ "Expiration": "expiry-date=\"Thu, 01 Oct 2020 09:07:49 GMT\", rule_id=\"rule2\"", "ETag": "\"9762f8a803bc34f5340579d4446076f7\"" }
For example, this HEAD Object request was used to get metadata for the same object in the testbucket bucket.
aws s3api --endpoint-url <StorageGRID endpoint> head-object --bucket testbucket --key obj2test2
The success response includes the object's metadata and indicates that the object will expire in 100 days and that it matched Rule 2.
{ "AcceptRanges": "bytes", "Expiration": "expiry-date=\"Thu, 01 Oct 2020 09:07:48 GMT\", rule_id=\"rule2\"", "LastModified": "2020-06-23T09:07:48+00:00", "ContentLength": 921, "ETag": "\"9762f8a803bc34f5340579d4446076f7\"" "ContentType": "binary/octet-stream", "Metadata": {} }