5

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?

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.