Search code examples
aws-lambdaserverlessaws-amplifydynamodb-queries

GET request with query parameters returns 403 error (signature does not match) - AWS Amplify


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?


Solution

  • 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.