Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a "folder-like" (i.e. PREFIX) object on S3 using the AWS CLI?

It is usually explained that there are no folders/directories on S3, which is true, however there are PREFIX objects. In some cases - e.g. using riofs to "mount" a filesystem to S3 - it could actually be useful to know how to create one of these.

Does anyone know if there is a "correct" way to do this with the AWS CLI? It's likely possible using the low-level API aws s3api ...

Related SO posts:

Amazon S3 boto - how to create a folder?

Creating a folder via s3cmd (Amazon S3)

P.S.

I also want to point out that in the AWS console this action is actually named "Create Folder...", so it's not really fair to tell people that there is no "concept" of a folder on S3.

Many thanks!

like image 361
Cawb07 Avatar asked Oct 13 '15 21:10

Cawb07


People also ask

Can S3 object be a folder?

Amazon S3 is a highly-scalable object storage system. Amazon S3 can contain any number of objects (files), and those objects can be organized into “folders”. However, to S3, folders don't really exist.

Can we create folder inside S3 bucket?

When you use the Amazon S3 console to create a folder, Amazon S3 creates a 0-byte object with a key that's set to the folder name that you provided. For example, if you create a folder named photos in your bucket, the Amazon S3 console creates a 0-byte object with the key photos/ .


1 Answers

After some quick fiddling around I found this seems to work:

aws s3api put-object --bucket test --key dir-test/

But it only works if you include the "/" at the end of the argument to --key. That part just didn't feel right... surely there's a better way?

like image 183
Cawb07 Avatar answered Sep 22 '22 04:09

Cawb07