Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create a bucket in S3 using ruby aws-sdk v2

When trying to create a new bucket in an S3 account using the ruby aws-sdk version 2, I always get the following exception:

NoMethodError: undefined method `location_name' for nil:NilClass
  index_members_by_location_name at /home/ubuntu/.rvm/gems/jruby-1.7.4/gems/aws-sdk-core-2.0.21/lib/seahorse/model/shapes.rb:283
...

I initialized the S3 client with the correct region and correct credentials. The following is part of my sample code:

...
s3 = Aws::S3::Client.new(region: region, credentials: credentials)

bucket = s3.create_bucket(bucket: 'mynewbucket')
puts bucket.inspect

# List the available buckets
puts "Available buckets:"
resp = s3.list_buckets
resp.buckets.each do |bucket|
    puts bucket.inspect
end

One note is that the code that lists the buckets works fine. Anyone knows what am I doing wrong?

EDIT:

I even added this code in order to list the objects in an existing bucket, and it throws the exact same error as above:

resp = s3.list_objects(bucket: 'existingbucket')
resp.contents.each do |object|
  puts "#{object.key} => #{object.etag}"
end
like image 744
Roland Pish Avatar asked Jan 24 '26 19:01

Roland Pish


1 Answers

That error is caused by a bug in JRuby 1.7.4 and how it handles the enumerable #inject and #each.with_object. Upgrading JRuby will resolve this issue.

like image 86
Trevor Rowe Avatar answered Jan 27 '26 00:01

Trevor Rowe



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!