功能在本地运行,但不在AWS Lambda

时间:2018-03-29 18:31:04

标签: aws-lambda jsreport

我正在使用jsreport呈现HTML并生成PDF文件,并且它在本地运行,但在Lambda上,它会抛出此错误:

{
  "errorMessage": "Error during rendering report: Cannot read property 'filter' of undefined",
  "errorType": "TypeError",
  "stackTrace": [
    "Phantom.execute (/var/task/node_modules/jsreport-phantom-pdf/lib/phantom.js:169:53)",
    "/var/task/node_modules/jsreport-core/lib/render/render.js:118:23",
    "tryCatcher (/var/task/node_modules/bluebird/js/release/util.js:16:23)",
    "Promise._settlePromiseFromHandler (/var/task/node_modules/bluebird/js/release/promise.js:512:31)",
    "Promise._settlePromise (/var/task/node_modules/bluebird/js/release/promise.js:569:18)",
    "Promise._settlePromise0 (/var/task/node_modules/bluebird/js/release/promise.js:614:10)",
    "Promise._settlePromises (/var/task/node_modules/bluebird/js/release/promise.js:693:18)",
    "Async._drainQueue (/var/task/node_modules/bluebird/js/release/async.js:133:16)",
    "Async._drainQueues (/var/task/node_modules/bluebird/js/release/async.js:143:10)",
    "Immediate.Async.drainQueues (/var/task/node_modules/bluebird/js/release/async.js:17:14)",
    "runCallback (timers.js:672:20)",
    "tryOnImmediate (timers.js:645:5)",
    "processImmediate [as _immediateCallback] (timers.js:617:5)"
  ]
}

相同的环境变量,相同的Node版本。

2 个答案:

答案 0 :(得分:1)

以下是生成上述错误的行:https://github.com/jsreport/jsreport-phantom-pdf/blob/ad8d42e640348abffe77f2fed818528bee3eed98/lib/phantom.js#L169

var phantom = this.definition.options.phantoms.filter(function (p) {
  return p.version === request.template.phantom.phantomjsVersion
})

表示对象路径options.phantoms未定义。

您必须检查Lambda中definitions的设置方式。

答案 1 :(得分:0)

事实证明,这是该库的一个问题:node-app-root-path

我通过将正确的rootDirectory选项传递给jsreport来修复它。