-
-
Save chroto/41c356402a19442b2de1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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