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:GetBucketLocation throwing error #380

Closed
jitcompile opened this issue Sep 14, 2015 · 5 comments
Closed

S3:GetBucketLocation throwing error #380

jitcompile opened this issue Sep 14, 2015 · 5 comments
Labels
bug This issue is a bug.

Comments

@jitcompile
Copy link

Calling S3.GetBucketLocation with a bucket name throws the following error. Ideally the exception should be caught, processed and the information shown as LocationConstraint output field.

AuthorizationHeaderMalformed: The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'ap-southeast-2' status code: 400, request id:

@jasdel
Copy link
Contributor

jasdel commented Sep 15, 2015

Hi @jitcompile thanks for reporting this issue. When you encountered this issue, was the region specified as us-east-1? In addition was the Config.Endpoint value set for this operation request? I'm trying to reproduce the issue you're seeing with the below code, but it's coming back with the correct response.

If you could add your configuration, and even better HTTP body output like in the following sample it would be very helpful.

package main

import (
    "fmt"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/s3"
)

func main() {
    svc := s3.New(aws.NewConfig().
        WithLogLevel(aws.LogDebugWithHTTPBody).
        WithRegion("us-east-1"))

    res, err := svc.GetBucketLocation(&s3.GetBucketLocationInput{
        Bucket: aws.String("bucket-thats-in-ap-southeast-1"),
    })

    fmt.Println(res, err)
}

@jasdel jasdel added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 15, 2015
@jitcompile
Copy link
Author

Hi @jasdel,

I've tried to log the http body and here's the printed message. The last line is from my own logging where I log the *aws.config.region value to screen.

2015/09/16 13:59:58 DEBUG: Request s3/GetBucketLocation Details:
---[ REQUEST POST-SIGN ]-----------------------------
GET http://test-sydney-files.s3.amazonaws.com/?location= HTTP/1.1
Host: test-sydney-files.s3.amazonaws.com
User-Agent: aws-sdk-go/0.9.6
Authorization: AWS4-HMAC-SHA256 Credential=xxx/20150916/us-east
-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=4b232a21998cd4e6882
ec59b5e93726a956ffb536987f8352dfdb7dbb40888ec
X-Amz-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b78
52b855
X-Amz-Date: 20150916T125958Z
Accept-Encoding: gzip


-----------------------------------------------------
2015/09/16 14:00:00 DEBUG: Response s3/GetBucketLocation Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 400 Bad Request
Connection: close
Transfer-Encoding: chunked
Content-Type: application/xml
Date: Wed, 16 Sep 2015 13:01:36 GMT
Server: AmazonS3
X-Amz-Id-2: 0MT1cYHUfyZBuoI0nRHyphzT9dB3WIij5ywRuacXhaCDjKjrprNa5QaPxkl8zkEjruwo
RsKIUm4=
X-Amz-Request-Id: 34964AD6A7A64A4A

177
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AuthorizationHeaderMalformed</Code><Message>The authorization heade
r is malformed; the region 'us-east-1' is wrong; expecting 'ap-southeast-2'</Mes
sage><Region>ap-southeast-2</Region><RequestId>34964AD6A7A64A4A</RequestId><Host
Id>0MT1cYHUfyZBuoI0nRHyphzT9dB3WIij5ywRuacXhaCDjKjrprNa5QaPxkl8zkEjruwoRsKIUm4=<
/HostId></Error>
0


-----------------------------------------------------
Client configuration region:  us-east-1

@jasdel
Copy link
Contributor

jasdel commented Sep 16, 2015

Thanks for the extra information. I think I figured this problem out. The GetBucketLocation should be using the S3 path style where the bucket name is apart of the URI path instead of host.

A workaround you can use until this is fixed is in your Config enable S3ForcePathStyle. This will ensure the S3 service client makes the request correctly for cross region bucket information.

svc := s3.New(aws.NewConfig().
        WithS3ForcePathStyle(true)

or

svc := s3.New(&aws.Config{S3ForcePathStyle: aws.Bool(true)})

@jasdel jasdel added bug This issue is a bug. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Sep 16, 2015
@jitcompile
Copy link
Author

Thanks @jasdel for confirming the problem and the workaround.

I've a ugly hack in my code where I'm parsing the error using regex and getting the correct bucket location. I'll use the workaround that you suggested.

I'll wait for the final fix. Thank you and fantastic work with the sdk 👍

@jasdel jasdel closed this as completed in ffc9803 Sep 16, 2015
jasdel added a commit that referenced this issue Sep 16, 2015
@jasdel
Copy link
Contributor

jasdel commented Sep 16, 2015

Hi @jitcompile This bug was fixed in the SDK's latest release. If you sync with it you'll be able to use GetBucketLocation without setting the S3ForcePathStyle config option.

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

No branches or pull requests

2 participants