skyhookadventure / appsync-client

A lightweight Appsync client that signs requests for you - designed to be run server-side (e.g. on Lambdas)
MIT License
22 stars 3 forks source link

Signature needs region when using AppSync custom domains #28

Open danielsharvey opened 11 months ago

danielsharvey commented 11 months ago

When using AppSync custom domains (https://docs.aws.amazon.com/appsync/latest/devguide/custom-domain-name.html), the produced signature does not contain the region (cannot be inferred from URL) and so the auth fails.

I have tested a fix by inserting region: "ap-southeast-2", after line 34: https://github.com/skyhookadventure/appsync-client/blob/aeedb2bfda0a0d639906791bcfd12a682fa07ff4/src/createRequestObject.ts#L30-L42

Of note, the library does not report this error well. I have tested at fix by inserting the following in the the result.on("end", ... processing (line 21 below):

if (result.statusCode !== 200) {
  // reject(new Error(`Error: Status Code ${result.statusCode}`));
  console.log('STATUS CODE', result.statusCode);
  console.log('STATUS RESPONSE', rawResponseBody);
}

https://github.com/skyhookadventure/appsync-client/blob/aeedb2bfda0a0d639906791bcfd12a682fa07ff4/src/httpsRequestPromisified.ts#L20-L37

I can submit a PR soon unless someone beats me to it.

danielsharvey commented 11 months ago

This is probably the same / related to #24.