Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test AWS S3 get object method ?

I am using aws sdk for ruby to retrieve an object from a bucket then read it. My code is something like:

def import_from_s3 

  #initiate the client
  s3 = Aws::S3::Client.new({
      region:            region,
      access_key_id:     key_id,
      secret_access_key: secret
  })

  #Get the object
  resp = s3.get_object(bucket: bucket, key: key)
end

My question is how do I test this method without mocking it?

like image 200
Ahmad Al-kheat Avatar asked Oct 19 '25 06:10

Ahmad Al-kheat


1 Answers

Here is the documentation on how to go about it.

Stubbing the aws client response

I used the default stub and it worked just fine.

Aws.config[:s3] = {stub_responses: {get_object: {body: StringIO.new("XYZ")}}}

like image 149
Deepti Anand Avatar answered Oct 21 '25 19:10

Deepti Anand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!