-1

The following response was returned from S3 server:

<Error>
    <Code>BucketAlreadyOwnedByYou</Code>
    <Message>Your previous request to create the named bucket succeeded and you already own it.</Message>
    <BucketName>newbucket</BucketName>
    <Resource>/newbucket</Resource>
    <RequestId>15C79B745D6D5C78</RequestId>
    <HostId>1c8c1a3a-fe7a-472a-a401-b57d6997aa9e</HostId>
</Error>

How to get the xml response from S3 server by using aws-sdk-go when getting an error? I want all the xml response.

func createBucket(s *s3.S3) {
    out, err := s.CreateBucket(&s3.CreateBucketInput{
        Bucket: aws.String("newbucket"),
    })
}

It's not enough to use the err in my case.

Thank you for you time.

labulaka
  • 48
  • 8
  • The docs mention a [GoStriong()](https://godoc.org/github.com/aws/aws-sdk-go/service/s3#Error) method. Did you try that? – Jonathan Hall Sep 25 '19 at 07:22

1 Answers1

0

I have found the way:

    head := s3.GetObjectInput{Bucket: &bucket, Key: aws.String("a")}
    req, _ := fs.s3.GetObjectRequest(&head)
    req.Handlers.UnmarshalMeta.PushBack(func(req *request.Request) {
        defer req.HTTPResponse.Body.Close()

        //req.HTTPResponse.Header['x-amz-bucket-region']
        buf, err := ioutil.ReadAll(req.HTTPResponse.Body)
        fmt.Printf("err: %v", string(buf))
        return
    })
    req.Send()

go to https://github.com/aws/aws-sdk-go/issues/542#issuecomment-180893732 for more details.

labulaka
  • 48
  • 8