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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With