In linux to create nested folders, irrespective of the intermediate folders exist or not can be done using the below command.
mkdir -p /home/user/some_non_existing_folder1/some_non_existing_folder2/somefolder
Similar to this i want to create a nested folder structure in S3 and place my files there later
how can i do this using aws cli
2
Answers
currently i am using the above way to carry on with my work
Folders do not actually exist in Amazon S3.
For example, if you have an empty bucket you could upload a file to
invoices/january.txt
and theinvoices
folder will magically ‘appear’ without needing to be specifically created.Then, if you were to delete the
invoices/january.txt
object, then theinvoices
folder will magically ‘disappear’ (because it never actually existed).This works because the
Key
(filename) of an Amazon S3 object contains the full path of the object. The above object is not calledjanuary.txt
— rather, it is calledinvoices/january.txt
. The Amazon S3 console will make it appear as if the folder exists, but it doesn’t.If you click the Create folder button in the S3 management console, then a zero-length object is created with the name of the folder. This causes the folder to ‘appear’ because it contains a file, but the file will not appear (well, it does appear, but humans see it as a folder). If this zero-length object is deleted, the folder will ‘disappear’ (because it never actually existed).
Therefore, if you wish to create a directory hierarchy before uploading files, you could upload zero-length objects with the same names as the folders you want to create. You can use the
aws s3 cp
command to upload such a file.Or, just upload the files to where you want them to appear, and the folders will magically appear automatically.