跳至内容

Best way to exclude an object from s3 lifecycle rule

0

Hi there,

I want to create a lifecycle rule that deletes ALL objects in a bucket older than a month except the latest one. And I want to keep this latest backup forever until I manually remove it. I understand that I cannot exclude objects from lifecycle rules that match them. So, could you please suggest a workaround or the best way to implement this? E.g. manually copy or move this latest backup to other bucket, tag the objects to be deleted, use object lock, etc.

Thank you so much for your time and help. :)

已提问 2 年前2004 查看次数

1 回答
1

Hello.

Are the names of the objects obtained during backup the same?
If the names are the same, I think the easiest way is to enable versioning and create a lifecycle rule that deletes the old version after one month.
If the object name is different, I think you can create a Lambda function that tags the old object and set a lifecycle rule to delete the object with the target tag set.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-configuration-examples.html#lifecycle-config-ex1

专家

已回答 2 年前

专家

已审核 2 年前

专家

已审核 2 年前

  • Hi, Riku. The object names are different as they are creation date and time. For each customer, the backups are automatically created and uploaded to s3 every hour. Using the Lambda function, can I tag all objects except 3 latest objects/backups for each customer/prefix? These latest backups might be from a long time ago, e.g. 1 month ago, 3 years ago. Can I do that using a Lambda function? Thanks in advance.

  • I think it is possible if you just set tags on what is currently stored in S3. From now on, I think you can create a Lambda function that sets the tag on the previous object every time a new object is uploaded. I think it would be a good idea to record the latest object key in DynamoDB, etc., and then when a new object is uploaded to S3, set a tag on the object with the object key stored in DynamoDB.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

相关内容