简体   繁体   English

如何在AWS Lambda中使用phantomjs 2.0

[英]how to use phantomjs 2.0 in AWS Lambda

i downloaed phantomjs binary from https://github.com/bprodoehl/phantomjs/releases/ , test fine on my localhost. 我从https://github.com/bprodoehl/phantomjs/releases/下载了phantomjs二进制文件,在我的localhost上测试正常。

package and create aws lambda function 打包并创建aws 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);
        }

    })
}

but when test in lambda , always got 但是当在lambda中进行测试时,总会得到

{"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)"}

anybody has any idea ? 有谁有任何想法? thanks 谢谢

Not the answer you want, but it's not such a good idea to use Lambda for "big binary packages" like this. 不是你想要的答案,但是将Lambda用于这样的“大二进制包”并不是一个好主意。 I believe it is technically possible to do what you want, but keep in mind that PhantomJs has a pretty huge startup cost (memory+cpu) and so your lambda bill will probably be quite high for the value you are getting. 我相信技术上可以做你想做的事情,但请记住,PhantomJs的启动成本非常高(内存+ cpu),因此你的lambda账单可能会非常高。

I suggest you see if https://PhantomJsCloud.com can meet your needs in this situation. 我建议您看看https://PhantomJsCloud.com是否能满足您在这种情况下的需求。 (Disclosure: I wrote it) (披露:我写的)

If you continue down the Lambda path, try following this resource: https://github.com/justengland/phantom-lambda-template 如果继续沿着Lambda路径行进,请尝试遵循以下资源: https//github.com/justengland/phantom-lambda-template

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM