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?

Scott
  • 129
  • 10

1 Answers1

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
};
T.D. Stoneheart
  • 811
  • 4
  • 7