mhart / aws4

Signs and prepares Node.js requests using AWS Signature Version 4
MIT License
703 stars 176 forks source link

The request signature we calculated does not match the signature you provided #95

Closed congkhuong closed 5 years ago

congkhuong commented 5 years ago
const aws4 = require('aws4');
const axios = require('axios');
const foo = {
  action: 'onMessage'
}
let request = {
  host: 'gqqgmx0p51.execute-api.ap-southeast-2.amazonaws.com',
  url: 'https://gqqgmx0p51.execute-api.ap-southeast-2.amazonaws.com/cylocal/%40connections/d_Jb1fiESwMCFJg%3D',
  method: 'POST',
  path: 'cylocal/%40connections/d_Jb1fiESwMCFJg%3D',
  body: JSON.stringify(foo),
  region: 'ap-southeast-2',
  service: 'execute-api',
  headers: {
    'content-type': 'application/json'
  }
}

let signedRequest = aws4.sign(request,
  {
    accessKeyId: 'AKIARE6UQUTSGYG7WDER',
    secretAccessKey: '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',
  })

delete signedRequest.headers['Host']
delete signedRequest.headers['Content-Length']
delete signedRequest.headers['content-type']

console.log(signedRequest);

let response = axios(signedRequest)

response.then(mes => {
  console.log(123)
}).catch(err => {
  //console.log(234)
  console.log(err.response.data)
})
// handle response

I try to connect to API gate for service execute-api, then i got this error. The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. I'm sure that i using correct access key and Secret key. Any suggestion for this resolve this issue

mhart commented 5 years ago

Yes, please search all the other issues that mention this error – especially ones for axios