Friday, 17 March 2017

Phantomjscloud not working with aws lambda nodejs

Feeling painful to create a AWS lambda function, I was able to deploy the same micro service easily with Google Cloud Function, when I ported the same service from GCF to lambda with some changes in handling function like context in aws lambda and deployed the .zip of the project. It started throwing an unknown error shown below. The lambda function works well in local environment,

{
  "errorMessage": "callback called with Error argument, but there was a problem while retrieving one or more of its message, name, and stack"
}

and the logs showing a syntax error in the parent script where the code begins, but there is no syntax error in the index.js which I have confirmed by running node index.js, any way I have attached the code snippet of index.js at the bottom

START RequestId: 7260c7a9-0adb-11e7-b923-aff6d9a52d2d Version: $LATEST Syntax error in module 'index': SyntaxError END RequestId: 7260c7a9-0adb-11e7-b923-aff6d9a52d2d

I started to narrow down the piece of software that is causing the problem, I have removed all the dependencies and started including one by one and ran the lambda each time uploading the zip and finally found the culprit that caused the problem, it is phantomjscloud that is causing the problem.

when I include const phantomJsCloud = require('phantomjscloud') it is throwing out that error, even my npm_modules have phantomjscloud module included. are there any known glitches between aws lambda and phanthomjscloud, no clue how to solve this, feel free to ask any information if you feel that I have missed any thing.

Here the code that works well without including const phantomJsCloud = require('phantomjscloud')

global.async = require('async');
global.ImageHelpers = require('./services/ImageHelpers');
global.SimpleStorage = require('./services/SimpleStorage');
global.uuid = require('uuid');
global.path = require('path');

const phantomJsCloud = require('phantomjscloud')
const aadhaarController = require('./controllers/Aadhaar')
exports.handler = (event, context) => {
    // TODO implement
    aadhaarController.generateAadhaarCard(event,context);
};

below is that link of image showing the error

Error message from aws lambda function when phantomjscloud is included



via Murali Krishna

No comments:

Post a Comment