Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby AWS::S3::S3Object (aws-sdk): Is there a method for streaming data as there is with aws-s3?

In aws-s3, there is a method (AWS::S3::S3Object.stream) that lets you stream a file on S3 to a local file. I have not been able to locate a similar method in aws-sdk.

i.e. in aws-s3, I do:

File.open(to_file, "wb") do |file|
  AWS::S3::S3Object.stream(key, region) do |chunk|
    file.write chunk
  end
end

The AWS::S3:S3Object.read method does take a block as a parameter, but doesn't seem to do anything with it.

like image 699
Philip Wiebe Avatar asked Mar 08 '12 16:03

Philip Wiebe


People also ask

What is AWS S3 SDK?

Amazon Simple Storage Service (Amazon S3) is a web service that provides highly scalable cloud storage. Amazon S3 provides easy to use object storage, with a simple web service interface to store and retrieve any amount of data from anywhere on the web. The JavaScript API for Amazon S3 is exposed through the AWS.

How do I access an S3 bucket from AWS SDK?

Call the listBuckets method of the Amazon S3 service object to retrieve a list of your buckets. The data parameter of the callback function has a Buckets property containing an array of maps to represent the buckets. Display the bucket list by logging it to the console. // Load the AWS SDK for Node.

Does AWS use Ruby?

Get started quickly using AWS with the AWS SDK for Ruby. The SDK helps take the complexity out of coding by providing Ruby classes for many AWS services including Amazon S3, Amazon EC2, DynamoDB, and more.

What is Ruby SDK?

The Oracle Cloud Infrastructure SDK for Ruby enables you to write code to manage Oracle Cloud Infrastructure resources.


2 Answers

The aws-sdk gem now supports chunked reads of objects in S3. The following example gives a demonstation:

s3 = AWS::S3.new
File.open(to_file, "wb") do |file|
  s3.buckets['bucket-name'].objects['key'].read do |chunk|
    file.write chunk
  end
end
like image 166
Trevor Rowe Avatar answered Nov 30 '22 16:11

Trevor Rowe


At this time, not officially. I found this thread in the official AWS Ruby forum:

Does the ruby aws gem support streaming download from S3. Quoting AWS staff:

Unfortunately there is not a good solution baked into the aws-sdk gem. We are looking into way we could make this much simpler for the end user.

There's sample code for downloading in chunks. You might want to have a look at that for inspiration.

like image 38
awendt Avatar answered Nov 30 '22 17:11

awendt