Synchronously getting response from longrunning aws lambda function

Viewed 258

enter image description here

I'm experimenting with nodejs puppeteer and the serverless framework following https://hackernoon.com/a-crash-course-on-serverless-with-node-js-632b37d58b44 . I have a puppeteer function that takes around 45 seconds to run and returns some data.

I have a function called main in index.js using puppeteer which I have tested locally and is working correctly, which includes:

async function main() {

  const browser = await puppeteer.connect({
    browserWSEndpoint: 'wss://chrome.browserless.io/'
  });
  var page = await browser.newPage();
  await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');

...................

obj_arr.push(obj);

}

my handler.ls function includes:

'use strict';

// module.exports.main = async event => {
module.exports.main = event => {
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: 'main function executed!',
        main: module.exports.main(),
        input: event,
      },
      null,
      2
    ),
  };

Using the serverless framework I've uploaded the code to amazon lambda without error. I tried changing the boilerplate code in handler.js to try to run the function synchronously and avoid having to store the output somewhere else. I'm getting the error in the screenshot. Is this possible and if so what am I doing wrong?

0 Answers
Related