mhart / aws4

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

The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method #100

Closed bala-drg closed 4 years ago

bala-drg commented 4 years ago

i'm getting AWS signature mismatch when i send request to API Gateway using axios

let data = JSON.stringify({
    "action": "message",
    "data": 'testing'
  })

let request = {
  host: '<API GATEWAY ID>.execute-api.<AWS REGION>.amazonaws.com',
  url: 'https://<API GATEWAY ID>.execute-api.<AWS REGION>.amazonaws.com/dev/@connections/<CONNECTION ID>',
  path: 'dev/@connections/<CONNECTION ID>',
  service: 'execute-api',
  region: '<AWS REGION>',
  data: data,
  body: data,
  headers: {
    'Content-Type': 'application/json'
  }
}

let signedRequest = aws4.sign(request,
                {
                  secretAccessKey: '<AWS SECRET KEY>',
                  accessKeyId: '<AWS ACCESS KEY>'
                })

let response = axios(signedRequest)
MythologicalEngineer commented 4 years ago

@bala-drg Did you find any resolution to this? I'm having the same issue and it seems to have happened quite suddenly.

MythologicalEngineer commented 4 years ago

I found a fix that worked for me. You have to add body to the request and make it a string of the data object.

example: request.body = JSON.stringify(request.data);

Put that before the aws4.sign method and it works. The problem is due to how Axios uses data rather than body.

mhart commented 4 years ago

Closing as an issue with axios, not this library