栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用NodeJS在AWS Lambda上运行PhantomJS

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用NodeJS在AWS Lambda上运行PhantomJS

这是一个简单

PhantomJS
过程的完整代码示例,以形式启动
NodeJS
child_process

它也可以在github上找到。


index.js

var childProcess = require('child_process');var path = require('path');exports.handler = function(event, context) {    // Set the path as described here: https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/    process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];    // Set the path to the phantomjs binary    var phantomPath = path.join(__dirname, 'phantomjs_linux-x86_64');    // Arguments for the phantom script    var processArgs = [        path.join(__dirname, 'phantom-script.js'),       'my arg'    ];    // Launc the child process    childProcess.execFile(phantomPath, processArgs, function(error, stdout, stderr) {        if (error) { context.fail(error); return;        }        if (stderr) { context.fail(error); return;        }        context.succeed(stdout);    });}

phantom-script.js

var system = require('system');var args = system.args;// Example of how to get arguments passed from node script// args[0] would be this file's name: phantom-script.jsvar unusedArg = args[1];// Send some info node's childProcess' stdoutsystem.stdout.write('hello from phantom!')phantom.exit();

要获取可与Amazon Linux机器一起使用的PhantomJS二进制文件,请转到PhantomJS
Bitbucket页面
并下载

phantomjs-1.9.8-linux-x86_64.tar.bz2



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/448799.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号