s3 lifecycle rule involving tag but no days:

0

Hi, We wish to set S3 lifecycle rule(s) to expire (eventually delete) objects based on tag

We have a process (lambda) to locate certain object on a S3 and add an archived:true tag to them. And they are "deletion candidates". Understand lifecycle can set object to expire and eventually the background process will delete them

However, we could lifecycle rule allows to filter based on object tag, but under Lifecycle rule actions, if we chose

  • expire current versions of the objects -- then we have to set number of days after object creation (where the "days" here contradict with our intention which is based on tag, nothing to do with days)
  • permanently delete concurrent versions of the object --> then we have to set days after objects become concurrent.

So, it seems if we are filtering by tag, we have to involve "days after creation". Am I correct?
If lifecycle is not a good choice of "deleting or expiring objects based on tag without caring how many days it has been created", what are the good solutions? Maybe another lambda to scan s3 and delete objects based on tags?

asked 3 months ago151 views
1 Answer
0

Hi,

I think there are multiple ways to achieve this. But, for your scenario, you can try to do something like this:

  • Create a Lifecycle rule for expiration with Object tags as "archived: true", and expiration days after 1 day.
  • This should trigger the daily deletion of all the objects within the bucket with the specific tag.

I have not tested this functionality personally but it seems achievable. You can try to test it and perform a HeadObject API call on these objects to see if S3 has evaluated the object and determined if it's eligible for expiration. [1]

Alternatively, you can use a Lambda function triggered by an S3 event notification on tag addition, or scheduled notification. The function can check for the required tag and use the S3 SDK to delete the object.
Or, you can use AWS Batch to run one-off delete jobs on tagged objects. The job script can use AWS CLI commands like aws s3api delete-object to remove objects.

Hope this helps.

References:
[1] https://repost.aws/questions/QUouAaZs08T7GYuDu3OIGLsA/s3-lifecycle-rules-with-tag-filters
[2] https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-expire-general-considerations.html

profile picture
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions