How to copy all objects w .pdf to a specific S3 folder?


I have an Amazon S3 bucket, with a number of folders, all containing PDF files, I’m attempting to create a one time rake task I can run, that will gather all the PDF files and move them to my ‘Archive’ folder in the same bucket.

I’ve been trying for hours, and the documentation really only helps for cross bucket copying, perhaps someone could take a look at my rake task and tell me what they think?

 task move_old_documents: :environment do
bucket = Settings.file_storage.ocr_documents.s3_credentials.bucket
file_util =
file_util.move_objects(s3_objects) do |obj|

and the corresponding method in my S3Util.rb file:

 def move_objects(s3_objects)
        s3_client.list_objects({bucket: Settings.file_storage.ocr_documents.s3_credentials.bucket}).each do |obj|
          s3_client.copy_object({bucket: Settings.file_storage.ocr_documents.s3_credentials.bucket, copy_source: "/#{obj.key}", key: "DestinationBucketName/#{obj.key}"})

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs