S3 Object delete

1

I am using S3 Lifecycle policy to delete objects which are greater than 7 days but my folders are also being deleted along with the objects. Isn't there any way where my objects only are deleted and not folders. I know that S3 follows a flat file structure but there must be a way. Can someone help me in this ?

asked 2 years ago1248 views
2 Answers
2
Accepted Answer

Adding to Indranil's answer, the S3 console fakes folders for our pleasure (and confusion at times). If there's an object whose name ends in "/" then the S3 console will display it as a folder but to the underlying S3 service it's just another object. Similarly if you create a folder (e.g. "folder1") from within the S3 console then it will create a 0-size object with a "/" suffix on its name, e.g. "folder1/".

So to answer your question "isn't there any way", yes sort of. You can follow the same idiom as the S3 console and keep 0-sized objects named "folder1/", "folder2/" etc that will appear as folders in the console even when all other objects with those prefixes have been deleted. They will however appear as objects when you query the S3 API. Then add a filter to your Lifecycle rule, ticking "Specify minimum object size" and only delete objects > 0 bytes. I expect your 0-sized objects will remain.

EXPERT
answered 2 years ago
1

S3 is an object store and not a file system. So it doesn't have the notion of folders. Instead it uses what are known as prefixes, which may make it appear like you are using folders, but prefixes are just part of the key. If there isn't any object that is using a particular prefix, then that prefix has no valid reason to exist. If you need the prefix, it can be recreated the moment you create a new object that uses the prefix.

profile pictureAWS
EXPERT
answered 2 years ago
  • So, there isn't any where my folders are not impacted by lifecycle policy ?

  • Yes, if you use "Specify minimum object size" as in my answer a few days ago - did that not help?

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