By using AWS re:Post, you agree to the Terms of Use

Object deletion from a non version bucket


Hi Team,

I am facing some issue with my bucket object I have a requirement of deletion of objects with lifecycle or with object policy.

My requirement I have 10 folders in my bucket in that each folder again I have 2 folder in that each folder we have multiple objects so I want to keep only 2 latest object and delete all objects and I don't want to delete folders

Non-version bucket with individual objects Please help me to solve this puzzle

1 Answers
Accepted Answer

I don't believe that you can maintain a number of 'latest' versions using a lifecycle rule unless you are using a bucket versioning. I think the solution may be to use a Lambda function to review the files in your bucket and to remove the ones you don't need. This function could be scheduled as frequently as needed, or on PUT events using EventBridge.

answered a month 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