drmg17928
2016-11-29 01:44
浏览 110
已采纳

通过aws-sdk-go签名URL时,签名不匹配403错误

I followed instructions on this issue https://github.com/aws/aws-sdk-go/issues/467 which clearly documented how to create a pre-signed url for a PUT request. The goal is to presign the url, so I can directly upload images from the browser safely

key and secret are of course my current credentials that work with direct PutObject requests via the SDK

creds := credentials.NewStaticCredentials("key", "secret", "")

cfg := aws.NewConfig().WithRegion("us-west-2").WithCredentials(creds)
srv := s3.New(session.New(), cfg)

params := &s3.PutObjectInput{
    Bucket: aws.String("my-bucket"),
    Key:    aws.String("/local/test/filename"), 
}
req, _ := srv.PutObjectRequest(params)
url, err := req.Presign(15 * time.Hour)
if err != nil {
    fmt.Println("error signing request", err)
}

fmt.Println("URL", url)

```

I then take that URL and make a curl request. I get this response

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
    <AWSAccessKeyId>redacted</AWSAccessKeyId>
    <StringToSign>redacted</StringToSign>
    <SignatureProvided>redacted</SignatureProvided>
    <StringToSignBytes>redacted</StringToSignBytes>
    <CanonicalRequest>PUT
/local/test/filename
X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=redacted%2Fus-west-2%2Fs3%2F%20aws4_request&amp;X-Amz-Date=20161129T012909Z&amp;X-Amz-Expires=54000&amp;X-Amz-SignedHeaders=host
host:redacted.s3-us-west-2.amazonaws.com

host
UNSIGNED-PAYLOAD</CanonicalRequest>
    <CanonicalRequestBytes>redacted</CanonicalRequestBytes>
    <RequestId>redacted</RequestId>
    <HostId>redacted</HostId>
</Error>

any ideas why the presigned URL is providing me a signature that supposedly does not match? Again these same credentials are currently working for direct PutObject commands on my server

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题