Abdul Manaf Abdul Manaf - 2 months ago 25
Node.js Question

getting request parameter in aws lambda

i need to read request parameter from a lambda function.iam configure Body Mapping Templates on my api gateway get method like this

{
"val1": "$input.params('val1')",
"val2": "$input.params('val2')"
}


my Lambda function code is

exports.handler = (event, context, callback) => {
// TODO implement

var val1 = require('querystring').parse(event.params.val1);
var val2 = require('querystring').parse(event.params.val2);

callback(null, 'Hello from Lambda' + val1 +'test'+val2);
};


But when testing my api method, i got error "Process exited before completing request" with log

TypeError: Cannot read property 'val1' of undefined


What is the actual issue related with this setup?

rsp rsp
Answer

It means that event.params is undefined.

Shouldn't it be like this?

var val1 = require('querystring').parse(event.val1);
var val2 = require('querystring').parse(event.val2);
Comments