Abdul Manaf
Abdul Manaf

Reputation: 4993

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?

Upvotes: 5

Views: 7854

Answers (1)

rsp
rsp

Reputation: 111268

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);

Upvotes: 3

Related Questions