Ruby: Undefined method `bucket' for #<Aws::S3::Client>

Viewed 1484

Using the aws-sdk-s3 gem, I am currently able to upload items to buckets and create signed URLs, and am trying to determine if an object exists in a bucket or not. All the documentation I see says client.bucket('bucketname') should work, but in my case it is not. I've tried:

client.bucket('bucketname')
client.bucket['bucketname']
client.buckets('bucketname')
client.buckets['bucketname']

but none work. This suggestion using head_object is a possibility (https://github.com/cloudyr/aws.s3/issues/160), but I'm still curious why bucket isn't working.

DOCS:
https://gist.github.com/hartfordfive/19097441d3803d9aa75ffe5ecf0696da
https://docs.aws.amazon.com/sdk-for-ruby/v3/api/index.html#Resource_Interfaces

1 Answers

You should call bucket or buckets on Aws::S3::Resource instance and not on Aws::S3::Client instance as an error states.

And the links you provided as well as docs show that:

s3 = Aws::S3::Resource.new(
  region: 'us-east-1',
  credentials: Aws::InstanceProfileCredentials.new()
)
bucket =  s3.bucket('my-daily-backups')
Related