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?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠