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?

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

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

回答问题的准则