Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 811
Abdul Manaf Avatar asked Oct 18 '22 01:10

Abdul Manaf


1 Answers

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);
like image 192
rsp Avatar answered Oct 20 '22 21:10

rsp