How to download amazon s3 files with the AWS::S3 ruby gem

The AWS::S3 gem is very convenient, but it was not immediately apparent to me how you could use it to download private files from amazon s3. It took me a while to figure this out, so hopefully it will help someone.

1. Connect to your s3 as usual
2. Find the file: file = S3Object.find 'filename.zip','filebucketname'
3. Open a file write: myfile = File.open('local-filename.zip','w')
4. Put the content: myfile.puts file.value

If someone knows a better way, I would love to know it.

  • I had to open the file with wb instead of w and ended using myfile.write but I was looking for this Thanks.