简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM