Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3 bucket existence - unexpected behavior #1161

Closed
Techbrunch opened this issue Apr 18, 2016 · 9 comments
Closed

s3 bucket existence - unexpected behavior #1161

Techbrunch opened this issue Apr 18, 2016 · 9 comments

Comments

@Techbrunch
Copy link

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>'
@awood45
Copy link
Member

awood45 commented Apr 18, 2016

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

@awood45
Copy link
Member

awood45 commented Apr 18, 2016

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
Copy link
Member

awood45 commented Apr 18, 2016

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.

trevorrowe added a commit that referenced this issue Apr 18, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Fixed the following issue:

  s3 = Aws::S3::Resource.new(region: 'us-west-1')

  s3.bucket('us-west-2-bucket-you-dont-own').exists?
  #=> raises Aws::S3::Errors::BadRequest

If the bucket exists, but you are configured for the incorrect region,
the SDK fails to extract the actual bucket region from the 400 response.
This is due to the fact that HEAD reponses do not have a body.

Added a check for the "x-amz-bucket-region" header before checking the
body. This the SDK to determine the proper signing region for the
request.

This change currently lacks tests.

See #1161
@awood45
Copy link
Member

awood45 commented Apr 18, 2016

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.

trevorrowe added a commit that referenced this issue Apr 18, 2016
Resolved the following issues:

  s3 = Aws::S3::Client.new(region: 'us-west-1')
  s3.head_bucket(bucket: 'us-west-2-bucket')
  #=> raises Aws::S3::Errors::BadRequest (without a message)

If the bucket exists, but you are configured for the incorrect region,
the SDK fails to extract the actual bucket region from the 400 response.
This results in an empty error message. Added support for loading the
bucket region from the "x-amz-bucket-region" header, which is necessary
for all HEAD responses.

Fixes #1161
@awood45
Copy link
Member

awood45 commented Apr 18, 2016

Thanks for the report!

@Techbrunch
Copy link
Author

@awood45 Awesome thanks for the quick fix !

trevorrowe added a commit that referenced this issue Apr 19, 2016
@ravsom
Copy link

ravsom commented Sep 5, 2017

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.

@raheel0452
Copy link

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

@ravsom
Copy link

ravsom commented Nov 24, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants