Javascript AWS Lambda函数:无法读取属性';日志'';页数'';溪流';未定义的。包装问题还是AWS Lambda问题?
我在AWS Lambda上使用带有Nodejs的幻影html到pdf包将html转换为pdf函数。我遇到了一些错误,这表明 无法读取未定义的属性“日志” 我试着对它进行注释,它显示了另一个错误,即 无法读取未定义的属性“numberOfPages” 我不确定这是软件包的错误还是因为它在AWS Lambda上不起作用。也不确定为什么async中的所有函数都不工作 代码如下:Javascript AWS Lambda函数:无法读取属性';日志'';页数'';溪流';未定义的。包装问题还是AWS Lambda问题?,javascript,node.js,aws-lambda,html-to-pdf,Javascript,Node.js,Aws Lambda,Html To Pdf,我在AWS Lambda上使用带有Nodejs的幻影html到pdf包将html转换为pdf函数。我遇到了一些错误,这表明 无法读取未定义的属性“日志” 我试着对它进行注释,它显示了另一个错误,即 无法读取未定义的属性“numberOfPages” 我不确定这是软件包的错误还是因为它在AWS Lambda上不起作用。也不确定为什么async中的所有函数都不工作 代码如下: const fs = require("fs"); var phantomjs = require("phantomjs")
const fs = require("fs");
var phantomjs = require("phantomjs");
const conversion = require("phantom-html-to-pdf")({});
exports.handler = (event, context, callback) => {
console.log("Start");
conversion(
{ html: "<h1>Hello World</h1>" },
// eslint-disable-next-line handle-callback-err
async (err, pdf) => {
const output = fs.createWriteStream("output.pdf");
console.log("Process");
console.log(pdf.logs);
console.log(pdf.numberOfPages);
// since pdf.stream is a node.js stream you can use it
// to save the pdf to a file (like in this example) or to
// respond an http request.
pdf.stream.pipe(output);
console.log("Done");
callback(null, "done");
}
);
console.log("End");
};
更新
我试着改变任何我想要的名字,效果很好。如果我删除pdf
,它就是不起作用。与上一个错误相同的问题。这里到底发生了什么
const fs = require("fs");
var AWS = require("aws-sdk");
var phantomjs = require("phantomjs");
const conversion = require("phantom-html-to-pdf")({});
exports.handler = (event, context, callback) => {
console.log("Start");
conversion(
{ html: "<h1>Hello World</h1>" },
// eslint-disable-next-line handle-callback-err
function(err, haha) {
const output = fs.createWriteStream("output.pdf");
console.log("Process");
//console.log(test.logs);
//console.log(test.numberOfPages);
// since pdf.stream is a node.js stream you can use it
// to save the pdf to a file (like in this example) or to
// respond an http request.
haha.stream.pipe(output);
console.log("Done");
callback(null, "done");
}
);
console.log("End");
};
const fs=require(“fs”);
var AWS=要求(“AWS sdk”);
var phantomjs=require(“phantomjs”);
const conversion=require(“幻影html到pdf”)({});
exports.handler=(事件、上下文、回调)=>{
控制台日志(“启动”);
转化(
{html:“你好,世界”},
//eslint禁用下一行句柄回调错误
功能(呃,哈哈){
const output=fs.createWriteStream(“output.pdf”);
控制台日志(“进程”);
//console.log(test.log);
//控制台日志(test.numberOfPages);
//因为pdf.stream是一个node.js流,所以您可以使用它
//将pdf保存到文件(如本例所示)或
//响应http请求。
哈哈。流。管(输出);
控制台日志(“完成”);
回调(空,“完成”);
}
);
控制台日志(“结束”);
};
我认为这不是lambda的问题。看起来pdf
为空-我认为您应该在使用pdf
之前检查err
。另外,我认为函数不应该是async
。是的,我注意到pdf似乎是空的。我稍后会尝试在这里更新。
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: Cannot read property 'numberOfPages' of undefined",
"trace": [
"Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'numberOfPages' of undefined",
" at process.on (/var/runtime/index.js:37:15)",
" at process.emit (events.js:198:13)",
" at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)",
" at process._tickCallback (internal/process/next_tick.js:69:34)"
]
}
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: Cannot read property 'stream' of undefined",
"trace": [
"Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'stream' of undefined",
" at process.on (/var/runtime/index.js:37:15)",
" at process.emit (events.js:198:13)",
" at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)",
" at process._tickCallback (internal/process/next_tick.js:69:34)"
]
}
const fs = require("fs");
var AWS = require("aws-sdk");
var phantomjs = require("phantomjs");
const conversion = require("phantom-html-to-pdf")({});
exports.handler = (event, context, callback) => {
console.log("Start");
conversion(
{ html: "<h1>Hello World</h1>" },
// eslint-disable-next-line handle-callback-err
function(err, haha) {
const output = fs.createWriteStream("output.pdf");
console.log("Process");
//console.log(test.logs);
//console.log(test.numberOfPages);
// since pdf.stream is a node.js stream you can use it
// to save the pdf to a file (like in this example) or to
// respond an http request.
haha.stream.pipe(output);
console.log("Done");
callback(null, "done");
}
);
console.log("End");
};