pedro.olimpio pedro.olimpio - 1 year ago 56
Node.js Question

How can I integrate API Gateway with Lambda through GET method

I'm deeply confused trying to integrate

AWS API Gateway
with
AWS Lambda
, because i'm trying to execute a lambda function through the
GET
method and always my function is returning invalid parameter.


{"errorMessage":"Error - Invalid Group ID - undefined - alexa id:
undefined"}|


It happens because the parameters was not arriving to the function and
idgrupo
variable is
<=0
.

I'm trying to execute a lambda function with
URL
at this form:

domain.execute-api.us-east-1.amazonaws.com/prod/chkneopairtoken?idgrupo=3823&clientId={321356-6666-4745}&keypair=90809276


And in my Lambda function i'm doing it:

var idgrupo = event.idgrupo;
var alexaClientId = event.clientId;
var keypair = event.keypair;

if (idgrupo > 0){

} else{
console.log("Error - Invalid Group ID - " + idgrupo + " - alexa id: " + alexaClientId + " - ");
//callback(null, "Error - Invalid Group ID - " + idgrupo + " - alexa id: " + alexaClientId);
context.fail("Error - Invalid Group ID - " + idgrupo + " - alexa id: " + alexaClientId);
}


Are there the possibility to do what i'm trying to do?
I think it is not an integration error between API Gateway and AWS Lambda, because the function returns my custom error message, and I believe it is a transfer parameters error.

Answer Source

Go back to the "Integration Request" of your resource GET, under "Body Mapping Templates"

  1. Select for the recommended option for "Request body passthrough"
  2. Add a mapping template (clicking on the action "Add mapping template")
  3. Write "application/json" for the content type
  4. Add this template

{
    "idgrupo" : "$input.params('idgrupo')",
    "clientId" : "$input.params('clientId')",
    "keypair" : "$input.params('keypair')"
}