Rashida
Rashida

Reputation: 91

Inconsistent behavior in Amazon S3 for folder/key upload, delete through console

There seems to be some inconsistency in Amazon S3's behavior. If in bucket a "Bucket1", I create folder "Folder1" and upload a file say "sample.txt" into it. Next I delete this file. At the bucket level I can see "Folder1" on S3 Console. Now in the same bucket if I upload a file "Folder2/sample.txt" and just delete sample.txt file, then Folder2 also disappears from console?

Why this inconsistency? AFAIK we do not have any API to create/delete folder at SDK level.

Am I missing something here or is this an actual issue?

Thanks in advance for any help.

Upvotes: 0

Views: 148

Answers (1)

Matt Houser
Matt Houser

Reputation: 36103

A "Folder" in S3 is simply a 0-byte object with a / character at the end of the key name.

So, using the AWS CLI or SDKs, you can "create a folder" by "putting" an object that matches those criteria.

The AWS Management Console also does something extra: it simulates folders, even of they were not explicitly created. So, if you uploaded your object as "Folder2/sample.txt", it extrapolates and simulates "Folder2/" at the parent folder level. You can do this yourself with the CLI/SDKs using the delimiter parameter.

When you delete that object, since "Folder2" did not actually exist as a 0-byte object ending with / (see first paragraph), then "Folder2/" disappears from the management console.

Upvotes: 2

Related Questions