aws-sdk-ruby icon indicating copy to clipboard operation
aws-sdk-ruby copied to clipboard

s3 bucket existence - unexpected behavior

Open Techbrunch opened this issue 10 years ago • 9 comments

Same issue as #796, looks like a regression (aws-sdk (2.2.34))

require 'aws-sdk'

resource = Aws::S3::Resource.new(region: 'us-east-1')

bucket = resource.bucket('test-issue-s3')
if bucket.exists?
  puts "test"
end
/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/aws-sdk-resources-2.2.34/lib/aws-sdk-resources/resource.rb:134:in `rescue in exists?': Aws::S3::Errors::BadRequest
    from /.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/aws-sdk-resources-2.2.34/lib/aws-sdk-resources/resource.rb:131:in `exists?'
    from test.rb:6:in `<main>'

Techbrunch avatar Apr 18 '16 22:04 Techbrunch

I am able to replicate the regression, taking a look.

awood45 avatar Apr 18 '16 22:04 awood45

Interestingly, the exact choice of bucket name here matters. The bucket 'test-issue-s3' is in the ap-northeast-1 region. So, for example, this code works:

Aws::S3::Resource.new(region: "ap-northeast-1").bucket('test-issue-s3').exists? #=> true

The issue here comes from the 307 Temporary Redirect we're getting. I get a similar issue if I try to hit a bucket I own in the "eu-central-1" region from a client in "us-east-1".

awood45 avatar Apr 18 '16 22:04 awood45

Looking back at some previous versions, I don't think this is a regression, I don't think this particular case has ever worked. Looking at fix options. I don't think I want to add 400 Bad Request as a successful waiter case, however.

awood45 avatar Apr 18 '16 22:04 awood45

So, the fix here (as Trevor is wrapping up) is to check for the bucket region in headers as well as the body. That will resolve this issue and similar. It's not often encountered because this particular failure modality was not hit by most client methods.

awood45 avatar Apr 18 '16 23:04 awood45

Thanks for the report!

awood45 avatar Apr 18 '16 23:04 awood45

@awood45 Awesome thanks for the quick fix !

Techbrunch avatar Apr 19 '16 08:04 Techbrunch

I get this error for the region "ap-south-1" - Should I raise a new issue?

S3 client configured for "ap-south-1" but the bucket "dev-embryo-ui" is in "ap-south-1"; Please configure the proper region to avoid multiple unnecessary redirects and signing attempts

/home/travis/.rvm/gems/ruby-2.2.7/gems/aws-sdk-resources-2.10.38/lib/aws-sdk-resources/resource.rb:134:in rescue in exists?': Aws::S3::Errors::BadRequest from /home/travis/.rvm/gems/ruby-2.2.7/gems/aws-sdk-resources-2.10.38/lib/aws-sdk-resources/resource.rb:131:in exists?'

I've created the bucket in the same region as I ask Travis to deploy. Despite that, I run into this issue.

ravsom avatar Sep 05 '17 01:09 ravsom

@ravsom did you ever get solution to above error ? i'm saving same issue

raheel0452 avatar Nov 24 '17 05:11 raheel0452

Not really. I changed the workflow to use s3 directly for static web hosting instead of directing it to eb.

On 24 Nov 2017 10:34 am, "raheel0452" [email protected] wrote:

@ravsom https://github.com/ravsom did you ever get solution to above error ? i'm saving same issue

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aws/aws-sdk-ruby/issues/1161#issuecomment-346743647, or mute the thread https://github.com/notifications/unsubscribe-auth/ADwkltSF_ivsEB0UprDE_1uDLcltT_ABks5s5k5KgaJpZM4IKK5f .

ravsom avatar Nov 24 '17 05:11 ravsom