Skip to content

Instantly share code, notes, and snippets.

@chroto
Forked from slotrans/lambda_test_harness.js
Last active August 29, 2015 14:16
Show Gist options
  • Save chroto/41c356402a19442b2de1 to your computer and use it in GitHub Desktop.
Save chroto/41c356402a19442b2de1 to your computer and use it in GitHub Desktop.
var fs = require('fs');
// Lambda knows what region it's in but a local execution doesn't, so preload the SDK and set the region
// This will only work if the same variable name is used in the Lambda function file
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
// validate arguments
if(process.argv.length < 4) {
console.error('Usage: node lambda_test_harness.js <function file> <input file>');
process.exit(1);
}
var context = {};
context.done = function(errorMessage, exitMessage) {
var exitCode = 0;
if(errorMessage) {
console.error(errorMessage);
exitCode = 1;
}
console.log(exitMessage);
process.exit(exitCode);
}
var exports = {};
var fileToInclude = process.argv[2];
eval(fs.readFileSync(fileToInclude).toString());
var inputFile = process.argv[3];
var inputEvent = JSON.parse(fs.readFileSync(inputFile).toString());
// assume you're using the conventional function name
exports.handler(inputEvent, context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment