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. :)

AKMin
asked 3 months ago615 views
1 Answer
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

profile picture
EXPERT
answered 3 months ago
profile picture
EXPERT
reviewed 3 months ago
profile pictureAWS
EXPERT
reviewed 3 months ago
  • 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.

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