I know how to set up API Gateway and link it to a Lambda function. What I don't know, and God have I searched, is how to get the response body from API Gateway in Lambda.
How do I get it? I see it when I test the API in the AWS console.
I know how to set up API Gateway and link it to a Lambda function. What I don't know, and God have I searched, is how to get the response body from API Gateway in Lambda.
How do I get it? I see it when I test the API in the AWS console.
I think you have to setup Body Mapping Template. Goto Gateway API -> API That you created -> Resources -> Method(Get/Post .. ) -> Integration Request -> Body Mapping Template -> Add Mapping Template
Content Type: application/json
{
"body" : $input.json('$'),
"headers": {
#foreach($header in $input.params().header.keySet())
"$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"params": {
#foreach($param in $input.params().path.keySet())
"$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end
#end
},
"query": {
#foreach($queryParam in $input.params().querystring.keySet())
"$queryParam": "$util.escapeJavaScript($input.params().querystring.get($queryParam))" #if($foreach.hasNext),#end
#end
}
}
You should be able to access the variables in Lambda
params.Item = event.query;
to access the query parameters
Check out these links for more information http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Let me know if that helps.