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 ?

已提問 2 年前檢視次數 1267 次
2 個答案
2
已接受的答案

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.

專家
已回答 2 年前
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
專家
已回答 2 年前
  • 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?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南