Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get only one level of objects in a S3 bucket?

Tags:

amazon-s3

I want to list only the objects in a bucket that aren't buckets themselves. Is there a way of doing this short of parsing out the results of ListBucket?

like image 349
Graham Chiu Avatar asked Mar 28 '11 06:03

Graham Chiu


People also ask

How do I make my S3 intelligent tiering?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want. Choose Properties. Navigate to the S3 Intelligent-Tiering Archive configurations section and choose Create configuration.

What is S3 infrequent access?

Amazon S3 Standard-Infrequent Access (S3 Standard-IA) S3 Standard-IA is for data that is accessed less frequently, but requires rapid access when needed. S3 Standard-IA offers the high durability, high throughput, and low latency of S3 Standard, with a low per GB storage price and per GB retrieval charge.

What is the best way to delete multiple objects from S3?

Navigate to the Amazon S3 bucket or folder that contains the objects that you want to delete. Select the check box to the left of the names of the objects that you want to delete. Choose Actions and choose Delete from the list of options that appears. Alternatively, choose Delete from the options in the upper right.

Is S3 object level storage?

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.


1 Answers

objects in a bucket that aren't buckets themselves

Buckets can't contain other buckets. Do you mean folders? S3 doesn't have a concept of folders either.

You can have 100 buckets per S3 account and each bucket can contain an unlimited number of objects/files. If you name your files with /'s in the filename, the AWS GUI tools (eg AWS Console, BucketExplorer etc) will interpret each section as a virtual folder. eg

A file named folder1/folder2/myfile.jpg will be stored in S3 as a 'flat' file with that name, but in the GUI tools it will appear as though a file named myfile.jpg is 2 subfolders down in folder1/folder2.

You can use the prefix and delimiter parameters to parse the results of a GET Bucket (List Objects) call. The same options are available in any of the SDKs too.

UPDATE to answer comment.

Assuming our S3 bucket looks like this:

mybucket
   folder1
      file1.txt
      file2.txt
      folder2
          file3.txt
          file4.txt
      folder3
          file5.txt
          file6.txt

Using prefix = "folder1/" would return all 6 files : file1.txt to file6.txt.

Using a prefix = "folder1/" and a delimiter = "/" would return 2 files:

    file1.txt
    file2.txt

And the CommonPrefixes collection of the response with contain

    folder1/folder2/
    folder1/folder3/
like image 107
Geoff Appleford Avatar answered Nov 14 '22 01:11

Geoff Appleford