2

Problem

I was trying to use 'aws-amplify' GET API request with query parameters on the client side, but it turned out to be Request failed with status code 403, and the response showed:

"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

Note: React.js as front-end, Javascript as back-end.

My code

Front-end
function getData() { 
  const apiName = 'MyApiName';
  const path = '/path';
  const content = { 
     body:{
        data:'myData',
    },
  };

  return API.get(apiName, path, content);
}
Back-end
try {
      const result = await dynamoDbLib.call("query", params);

    } catch (e) {
        return failure({ status: false });
    }

What I did to debug

  1. The GET lambda function works fine in Amazon Console (Tested)
  2. If I change the backend lambda function so that the frontend request can be made without parameters, i.e. return API.get(apiName, path), then no error shows up.

My question

How can I make this GET request with query parameters works?

Aso Sun
  • 21
  • 3

1 Answers1

0

I changed GET to POST (return API.post()), everything works fine now.

If anyone can provide a more detailed explanation, it would be very helpful.

Aso Sun
  • 21
  • 3
  • I am facing the same issue. I don't think that's a solution at all. you just changed the REST API's method type. Did you ever find the solution to make it work with REST GET API amplify? – Siddharth Choudhary Apr 29 '21 at 18:35
  • @SiddharthChoudhary In my case here, the query parameter is in the message body instead of appending it in URL string. POST method is what I was looking for. If you want to work with GET method, the parameters should be appended in the url string. You may refer to this [link](https://www.tutorialspoint.com/listtutorial/Difference-between-GET-and-POST-method-in-HTTP/3916#:~:text=method%20in%20HTTP.-,Both%20GET%20and%20POST%20method%20is%20used%20to%20transfer%20data,transferring%20data%20from%20client%20to) – Aso Sun May 01 '21 at 03:19
  • @SiddharthChoudhary If you want to insist on using GET method, you will have to change the authorization of that method from **AWS_IAM** to **None** from Amazon API Gateway – Aso Sun May 01 '21 at 03:35
  • Thanks for the response. I actually did find the solution and that was an issue with the AWS Amplify's IOS SDK and they way they were interpreting my arguments (having ' : '). It's probably related to the incorrect encoding which that SDK is internally trying to encode that into. Stupid AWS! – Siddharth Choudhary May 03 '21 at 15:42
  • Well, for my use case, I had a queryParameter like this:- "2021/04/23 17:23:23" and it was failing because Amplify's iOS SDK probably can't decode " : " or on some similar lines. So, I rather started sending the queryParameter as:- "20210423172323". Changed the format! But again, that's my use-case. – Siddharth Choudhary May 07 '21 at 14:32
  • I just experienced the same thing. The reason why you get a 403 error is because you are not allowed to send a body along in a GET request; this is not specific to aws-amplify but is how it is in general. Instead, you are supposed to send the data in the form of query params, or, as you figured out yourself, send a post request. – Sebastian Nielsen Nov 08 '22 at 20:35
  • @SiddharthChoudhary Thre is an open issue in github for amplify-swift. https://github.com/aws-amplify/amplify-swift/issues/2542 – Krishan Madushanka Jan 17 '23 at 10:29