Skip to content

Instantly share code, notes, and snippets.

@dimkir dimkir/index.js

Created Mar 13, 2017
What would you like to do?
Using NigthmareJS on AWS Lambda
'use strict';
// Code in global scope (outside of event) runs once, when container is first created
var pack = require('./lib/nightmare-lambda-pack');
var electronPath = pack.installNightmare(); // this will install the electron on the Lambda
var Xvfb = require('./lib/xvfb');
var Snapper = require('./lib/nightmare-snapper');
exports.handler = function(event, context){
// how do I know that by the time this was run, the pack was installed?
var url, xvfb, snapper;
if ( !event.url ){
context.done('Error please specify .url property on the event');
url = event.url;
xvfb = new Xvfb({
xvfb_executable : '/tmp/app/Xvfb' // will be part of package together with Electron
xvfb.start((err, xvfbProcess) => {
if (err){
console.error('Error starting xvfb', err);
return context.done(err);
snapper = new Snapper({
destBucket: 'rojet',
destBucketRegion: 'eu-west-1', // this is used to generate full screenshot url in form,
nightmareOptions: {
electronPath: electronPath
snapper.snap({ url: url })
.then((result) => {
stopXvfbAndFinish(null, result);
, (err) => {
function stopXvfbAndFinish(err, result){
xvfb.stop((err) => {
context.done(err, result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.