Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ $ node-lambda run --help
-h, --help output usage information
-h, --handler [index.handler] Lambda Handler {index.handler}
-j, --eventFile [event.json] Event JSON File
-u, --runtime [nodejs4.3] Lambda Runtime {nodejs4.3, nodejs} - "nodejs4.3" is the current standard, "nodejs" is v0.10.36
```

#### package
Expand Down Expand Up @@ -112,7 +113,7 @@ $ node-lambda deploy --help
-m, --memorySize [128] Lambda Memory Size
-t, --timeout [3] Lambda Timeout
-d, --description [missing] Lambda Description
-u, --runtime [nodejs] Lambda Runtime
-u, --runtime [nodejs4.3] Lambda Runtime {nodejs4.3, nodejs} - "nodejs4.3" is the current standard, "nodejs" is v0.10.36
-p, --publish [false] This boolean parameter can be used to request AWS Lambda to create the Lambda function and publish a version as an atomic operation
-v, --version [custom-version] Lambda Version
-f, --configFile [] Path to file holding secret environment variables (e.g. "deploy.env")`
Expand All @@ -124,6 +125,15 @@ $ node-lambda deploy --help

AWS Lambda doesn't let you set environment variables for your function, but in many cases you will need to configure your function with secure values that you don't want to check into version control, for example a DB connection string or encryption key. Use the sample `deploy.env` file in combination with the `--configFile` flag to set values which will be prepended to your compiled Lambda function as `process.env` environment variables before it gets uploaded to S3.

## Node.js Runtime Configuration

AWS Lambda now supports Node.js v4.3.2, and there have been some [API changes](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-using-old-runtime.html) for the new version. Most notably,
`context.done()`, `context.succeed()`, and `context.fail()` are deprecated in favor of the Node convention of passing in
a callback function. These will still work for now for backward compatibility, but are no longer recommended.

v0.10.36 is still supported, and can be targeted by changing the `AWS_RUNTIME` value to `nodejs` in the `.env` file.


## Other AWS Lambda Tools Projects

+ [lambdaws](https://github.com/mentum/lambdaws)
Expand Down
3 changes: 2 additions & 1 deletion bin/node-lambda
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var AWS_ROLE = process.env.AWS_ROLE_ARN || process.env.AWS_ROLE || 'missing';
var AWS_MEMORY_SIZE = process.env.AWS_MEMORY_SIZE || 128;
var AWS_TIMEOUT = process.env.AWS_TIMEOUT || 60;
var AWS_DESCRIPTION = process.env.AWS_DESCRIPTION || '';
var AWS_RUNTIME = process.env.AWS_RUNTIME || 'nodejs';
var AWS_RUNTIME = process.env.AWS_RUNTIME || 'nodejs4.3';
var AWS_PUBLISH = process.env.AWS_PUBLIS || false;
var AWS_FUNCTION_VERSION = process.env.AWS_FUNCTION_VERSION || '';
var AWS_VPC_SUBNETS = process.env.AWS_VPC_SUBNETS || '';
Expand Down Expand Up @@ -76,6 +76,7 @@ program
.description('Run your Amazon Lambda application locally')
.option('-h, --handler [' + AWS_HANDLER + ']', 'Lambda Handler {index.handler}', AWS_HANDLER)
.option('-j, --eventFile [' + EVENT_FILE + ']', 'Event JSON File', EVENT_FILE)
.option('-u, --runtime [' + AWS_RUNTIME + ']', 'Lambda Runtime', AWS_RUNTIME)
.action(function (prg) {
lambda.run(prg);
});
Expand Down
50 changes: 42 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,59 @@ Lambda.prototype.run = function (program) {
var handler = require(process.cwd() + '/' + filename)[handlername];
var event = require(process.cwd() + '/' + program.eventFile);

this._runHandler(handler, event);
this._runHandler(handler, event, program.runtime);
};

Lambda.prototype._runHandler = function (handler, event) {
Lambda.prototype._runHandler = function (handler, event, runtime) {

var callback = function (err, result) {
if (err) {
console.log('Error: ' + error);
process.exit(-1);
}
else {
console.log('Success:');
if (result) {
console.log(JSON.stringify(result));
}
process.exit(0);
}
};

var context = {
isNode43: runtime === "nodejs4.3",
succeed: function (result) {
console.log('succeed: ' + JSON.stringify(result));
process.exit(0);
if (isNode43) {
console.log('context.succeed() is deprecated with Node.js 4.3 runtime');
}
callback(null, result);
},
fail: function (error) {
console.log('fail: ' + error);
process.exit(-1);
if (isNode43) {
console.log('context.fail() is deprecated with Node.js 4.3 runtime');
}
callback(error);
},
done: function () {
process.exit(0);
if (isNode43) {
console.log('context.done() is deprecated with Node.js 4.3 runtime');
}
callback();
}
};

handler(event, context);
switch(runtime) {
case "nodejs":
handler(event, context);
break;
case "nodejs4.3":
handler(event, context, callback);
break;
default:
console.error("Runtime [" + runtime + "] is not supported.");
}


};

Lambda.prototype._params = function (program, buffer) {
Expand Down