这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion bin/run-local-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
file : 'index.js',
event : 'event.json',
timeout : 3000,
handler : 'handler'
handler : 'handler',
processenv : ''
};

/*
Expand All @@ -33,9 +34,11 @@
* --event, -e <event:string> #Name of the file containing the event object (Default: event.json)
* --timeout, -t <timeout:int> #The timeout in seconds (Default: 3 seconds)
* --handler, -h <handler:string> #Name of the handler function to invoke (Default: handler.exports)
* --processenv, -p <environment:string> #Name of the file containing the event object (Default: event.json)
*
* E.g. node run-local-lambda (providing index.js and event.json are in the current directory)
* E.g. node run-local-lambda --file index.js --event event.json --timeout 3 --memory 128 --handler handler
* E.g. node run-local-lambda --file index.js --event event.json --timeout 3 --memory 128 --handler handler --processenv environment.json
*/
var processArguments = function(settings) {
process.argv.forEach(function(argument, index, array){
Expand All @@ -50,6 +53,11 @@
break;
}

case '--processenv': {
settings.processenv = array[index+1];
break;
}

case '--timeout': {
settings.timeout = parseInt(array[index+1], 10) * 1000; //convert seconds to milliseconds
break;
Expand Down Expand Up @@ -125,9 +133,21 @@
process.exit();
}

function processEnv(settings){
if(settings.processenv!='') {
var processenv = require(path.resolve(settings.processenv, '.'));
for(var attributename in processenv){
process.env[ attributename] = processenv[attributename];
}
}
}

processArguments(settings);

processEnv(settings);

var event = require(path.resolve(settings.event, '.'));

var context = createContext(settings.timeout);

var lambda = require(path.resolve(settings.file, '.'));
Expand Down