├── LICENSE ├── README.md ├── index.js ├── package.json ├── phantom-script.js └── phantomjs_linux-x86_64 /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Tyler Pachal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | UPDATE 2 | === 3 | 4 | I have been told that this no longer works! I no longer use AWS/Lambda so for now the best I can do is link to an [alternate solution](https://stackoverflow.com/a/56843029/2282538). 5 | 6 | PRs are welcome to get this working again. 7 | 8 | 9 | 10 | lambda-node-phantom 11 | === 12 | 13 | A simple ~working~ example of running PhantomJS on AWS Lambda via NodeJS 14 | --- 15 | 16 | This repository contains a complete, working example of running a simple PhantomJS script on AWS Lambda through a NodeJS child process. 17 | 18 | First, clone this repository (or download the zip). Next, [compress the contents of the folder](http://stackoverflow.com/a/34640743/2282538), and upload the zip file to an AWS Lambda function. 19 | 20 | The PhantomJS binary is included in this repository, but if you would like to download it yourself you can get it from the [PhantomJS Bitbucket Page](https://bitbucket.org/ariya/phantomjs/downloads); download `phantomjs-1.9.8-linux-x86_64.tar.bz2`. 21 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var childProcess = require('child_process'); 2 | var path = require('path'); 3 | 4 | exports.handler = function(event, context) { 5 | 6 | // Set the path as described here: https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/ 7 | process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']; 8 | 9 | // Set the path to the phantomjs binary 10 | var phantomPath = path.join(__dirname, 'phantomjs_linux-x86_64'); 11 | 12 | // Arguments for the phantom script 13 | var processArgs = [ 14 | path.join(__dirname, 'phantom-script.js'), 15 | 'my arg' 16 | ]; 17 | 18 | // Launc the child process 19 | childProcess.execFile(phantomPath, processArgs, function(error, stdout, stderr) { 20 | if (error) { 21 | context.fail(error); 22 | return; 23 | } 24 | if (stderr) { 25 | context.fail(error); 26 | return; 27 | } 28 | context.succeed(stdout); 29 | }); 30 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lambda-node-phantom", 3 | "version": "1.0.0", 4 | "description": "A simple working example of running PhantomJS on AWS Lambda via NodeJS", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Tyler Pachal", 10 | "license": "MIT" 11 | } 12 | -------------------------------------------------------------------------------- /phantom-script.js: -------------------------------------------------------------------------------- 1 | var system = require('system'); 2 | var args = system.args; 3 | 4 | // Example of how to get arguments passed from node script 5 | // args[0] would be this file's name: phantom-script.js 6 | var unusedArg = args[1]; 7 | 8 | // Send some info node's childProcess' stdout 9 | system.stdout.write('hello from phantom!') 10 | 11 | phantom.exit(); -------------------------------------------------------------------------------- /phantomjs_linux-x86_64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TylerPachal/lambda-node-phantom/02fb0930b2a79e91243b4bd8e69cd6d71993ab89/phantomjs_linux-x86_64 --------------------------------------------------------------------------------