Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Sub folder in S3 Bucket?

Tags:

amazon-s3

Already i have Root bucket(Bigdate).now i want to create NEWFOLDER (year) inside Bigdate bucket in s3 bucket. then create NEWFOLDER(MONTH) inside year.

aws s3 mb s3://bigdata -->Bucket created

aws s3 mb s3://bigdata/Year/ --> It not working

like image 676
Vinoth_S Avatar asked Aug 05 '16 10:08

Vinoth_S


People also ask

Can we create folder inside S3 bucket?

You can have folders within folders, but not buckets within buckets. You can upload and copy objects directly into a folder. Folders can be created, deleted, and made public, but they cannot be renamed.

Is it better to have multiple S3 buckets or one bucket with sub folders?

The total volume of data and number of objects you can store are unlimited. Also the documentation states there is no performance difference between using a single bucket or multiple buckets so I guess both option 1 and 2 would be suitable for you.


2 Answers

Use the below syntax, this is what I am using to create bucket and subfolders. Don't forget the "/" at end of the folder name.

aws s3api put-object --bucket <your-bucket-name> --key <folder-name>/test.txt --body yourfile.txt
like image 139
error2007s Avatar answered Oct 23 '22 07:10

error2007s


If local file is foo.txt, and remote "folder" Year does not yet exist, then to create it, just put the file at the designated path:

$ aws s3 cp foo.txt s3://bigdata/Year/ --recursive

Or if local folder is YearData containing foo.txt, bar.txt,

$ aws s3 cp YearData s3://bigdata/Year/ --recursive
upload: YearData/foo.txt to s3://bigdata/Year/foo.txt
upload: YearData/bar.txt to s3://bigdata/Year/bar.txt

See also:

  • http://docs.aws.amazon.com/cli/latest/reference/s3/cp.html
  • http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html
  • and first, http://docs.aws.amazon.com/cli/latest/reference/configure
like image 42
michael Avatar answered Oct 23 '22 07:10

michael