如何在AWS Lambda中使用phantomjs 2.0

我从https://github.com/bprodoehl/phantomjs/releases/下载phantomjs二进制文件,在我的本地主机上testing很好。

打包并创buildaws lambda函数

exports.handler = function (event, context) { var path = require("path"); var Process = require("child_process"); Process.exec(path.join(__dirname,"./bin/phantomjs")+" --version", function (err, data) { if (err) { console.log(err.message); context.fail(err.stack); } else { context.succeed(data); } }) } 

但是在lambda中testing时,总是得到

 {"errorMessage":"Error: Command failed: /bin/sh: /var/task/bin/phantomjs: Permission denied at ChildProcess.exithandler (child_process.js:658:15) at ChildProcess.emit (events.js:98:17) at maybeClose (child_process.js:766:16) at Socket.<anonymous> (child_process.js:979:11) at Socket.emit (events.js:95:17) at Pipe.close (net.js:466:12)"} 

任何人有任何想法? 谢谢

不是你想要的答案,但是将Lambda用于这样的“大二进制包”并不是一个好主意。 我相信在技术上可以做到你想要的,但是请记住,PhantomJs有一个相当大的启动成本(内存+ CPU),所以你的lambda账单可能会相当高,你的价值。

我build议你看看https://PhantomJsCloud.com是否能在这种情况下满足你的需求&#x3002; (披露:我写了)

如果您继续使用Lambdapath,请尝试使用以下资源: https : //github.com/justengland/phantom-lambda-template