kndt84/aws-api-gateway-client

InvalidSignatureException on POST

Closed this issue · 2 comments

Hi, I am developing an angular2 application and started using this client. I am able to call GET API without problem, however API gateway returns InvalidSignatureException when POST API is called.

Can't seem to find the reason for the failure. Only the method type is changed between these 2 requests.
Would really appreciate some help here.

Response:
Connection:keep-alive Content-Length:913 Content-Type:application/json Date:Fri, 28 Apr 2017 09:00:22 GMT Via:1.1 cd506e499a8d4ba06493f1ac8ef2cb9c.cloudfront.net (CloudFront) X-Amz-Cf-Id:L3DRIihKtz28zy3wOM5_AUpCqSWp9VWvamJeajq0JHqyhfLV31wEMg== x-amzn-ErrorType:InvalidSignatureException x-amzn-RequestId:1c5b0889-2bf1-11e7-8dcc-038e5a6b122f X-Cache:Error from cloudfront

Request:
Accept and Content-Type is 'application/json'
Body is a JSON string

working for me as a POST

const config = {
  invokeUrl: 'https://xxxxxx.execute-api.us-east-1.amazonaws.com',
  region: 'us-east-1',
  accessKey: 'xxxxx',
  secretKey: 'xxxxxx',
  apiKey: 'xxxxxx',
};

  const apigClient = apigClientFactory.newClient(config);
  const params = {};
  const xtraParams = {};
  const body = {
    type: 'FeatureCollection',
    features: [feature],
  };
  return apigClient.invokeApi(params, '/Prod/mypath', 'POST', xtraParams, body),

Ah okay, finally figured out the reason. POST does not accept headers in the additionalParams, so I removed them and the request went through.

It is weird though, my GET and POST has CORS enabled, and allow the same headers to be passed.
Nevertheless, another valuable experience gained: Whenever I encounter an error that does not seem to have a discernible cause, just try to remove certain parts of the code to see if it works.