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!
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.
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/ .
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With