AWS S3 - How to fix 'The request signature we calculated does not match the signature' error?

后端 未结 30 2584
谎友^
谎友^ 2020-11-29 08:05

I have searched on the web for over two days now, and probably have looked through most of the online documented scenarios and workarounds, but nothing worked for me so far.

相关标签:
30条回答
  • 2020-11-29 08:22

    This error seems to occur mostly if there is a space before or after your secret key

    0 讨论(0)
  • 2020-11-29 08:22

    For me I used axios and by deafult it sends header

    content-type: application/x-www-form-urlencoded
    

    so i change to send:

    content-type: application/octet-stream
    

    and also had to add this Content-Type to AWS signature

    const params = {
        Bucket: bucket,
        Key: key,
        Expires: expires,
        ContentType = 'application/octet-stream'
    }
    
    const s3 = new AWS.S3()
    s3.getSignedUrl('putObject', params)
    
    0 讨论(0)
  • 2020-11-29 08:22

    In my case I was using s3.getSignedUrl('getObject') when I needed to be using s3.getSignedUrl('putObject') (because I'm using a PUT to upload my file), which is why the signatures didn't match.

    0 讨论(0)
  • 2020-11-29 08:25

    I had to set

    Aws.config.update({
      credentials: Aws::Credentials.new(access_key_id, secret_access_key)
    })
    

    before with the ruby aws sdk v2 (there is probably something similiar to this in the other languages as well)

    0 讨论(0)
  • 2020-11-29 08:25

    I don't know if anyone came to this issue while trying to test the outputted URL in browser but if you are using Postman and try to copy the generated url of AWS from the RAW tab, because of escaping backslashes you are going to get the above error.

    Use the Pretty tab to copy and paste the url to see if it actually works.

    I run into this issue recently and this solution solved my issue. It's for testing purposes to see if you actually retrieve the data through the url.

    This answer is a reference to those who try to generate a download, temporary link from AWS or generally generate a URL from AWS to use.

    0 讨论(0)
  • 2020-11-29 08:26

    I get this error with the wrong credentials. I think there were invisible characters when I pasted it originally.

    0 讨论(0)
提交回复
热议问题