I wanted to show a list of all files in an s3 folder so I can get all the last modified dates so I can determine what files has been changed.
I tried using objects.with_prefix('Folder1') it give me a full list but also contain Folder1.1 key
I don't know if i needed to use delimiter but I couldn't find anything how to use delimiter in aws sdk.
Thanks so much in advance!
I'm using 'aws-sdk' gem
Here is my bucket structure -Folder1 -File1 -File2 -Folder.1.1
Here is my code
bucket = s3.buckets[bucket_name] data = bucket.objects.with_prefix('Folder1/') data.each do |object| puts "#{object.key}\t#{object.last_modified}"; end
In AWS Explorer, expand the Amazon S3 node, and double-click a bucket or open the context (right-click) menu for the bucket and choose Browse. In the Browse view of your bucket, choose Upload File or Upload Folder. In the File-Open dialog box, navigate to the files to upload, choose them, and then choose Open.
aws s3 sync s3://mybucket . will download all the objects in mybucket to the current directory. This will download all of your files using a one-way sync. It will not delete any existing files in your current directory unless you specify --delete , and it won't change or delete any files on S3.
Open the AWS S3 console and click on your bucket's name. In the Objects tab, click the top row checkbox to select all files and folders or select the folders you want to count the files for. Click on the Actions button and select Calculate total size.
Too late answer but better than never.
You can do
s3_bucket.objects.with_prefix('folder_name').collect(&:key)
According to official documentation here
Updates: SDK V3
s3 = Aws::S3::Client.new resp = client.list_objects_v2({ bucket: "BucketName", # required prefix: "FolderName", })
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