1

I'm trying to follow the examples found here, but am not quite getting it. Here is what I have:

simpletest.js:

exports.handler = async (event) => {
    console.log('>> Handler called');

    const response = {
        statusCode: 200,
        body: JSON.stringify('Handler Data')
    };

    console.log('>> Response[1]: ' + JSON.stringify(response));
    return response;
};

simplerun.js

let process = require('./simpletest.js');

console.log(">> START");
process.handler(
  {}, // event
  {}, // context
  function(response,error) {
    console.log(">> Response[2]: " + response);
  }
);
console.log(">> END");

What I got:

% node simplerun.js
>> START
>> Handler called
>> Response[1]: {"statusCode":200,"body":"\"Handler Data\""}
>> END

What I expected:

% node simplerun.js
>> START
>> Handler called
>> Response[1]: {"statusCode":200,"body":"\"Handler Data\""}
>> Response[2]: {"statusCode":200,"body":"\"Handler Data\""}
>> END

Why isn't Response[2] being generated as expected?

1 Answer 1

2

In the handler function of simpletest.js, you haven't used the third parameter to call the desired callback function.

You might need to change the function to something like...

async (event, context, callback) => {
    console.log('>> Handler called');

    const response = {
        statusCode: 200,
        body: JSON.stringify('Handler Data')
    };

    console.log('>> Response[1]: ' + JSON.stringify(response));
    callback(response); // instead of returning, execute the callback
};
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.