简体   繁体   中英

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.

package and create aws lambda function

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

{"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. 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.

I suggest you see if https://PhantomJsCloud.com can meet your needs in this situation. (Disclosure: I wrote it)

If you continue down the Lambda path, try following this resource: https://github.com/justengland/phantom-lambda-template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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