aws-lambda
Advanced tools
Comparing version 0.0.9 to 0.0.10
"use strict"; | ||
var | ||
aws = require( "aws-sdk" ), | ||
exec = require( "child_process" ).exec, | ||
fs = require( "fs" ), | ||
os = require( "os" ), | ||
packageJson = require( "./../package.json" ), | ||
path = require( "path" ); | ||
var aws = require( "aws-sdk" ) | ||
var exec = require( "child_process" ).exec | ||
var fs = require( "fs" ) | ||
var os = require( "os" ) | ||
var path = require( "path" ) | ||
var Lambda = function( ) { | ||
this.version = packageJson.version; | ||
return this; | ||
}; | ||
Lambda.prototype.run = function( program ) { | ||
var | ||
dir = program.directory, | ||
splitHandler = program.handler.split( "." ), | ||
filename = splitHandler[0] + ".js", | ||
handlername = splitHandler[1]; | ||
var | ||
handler = require( process.cwd() + "/" + filename )[handlername], | ||
event = require( process.cwd() + "/event.json" ); | ||
this._runHandler( handler, event ); | ||
} | ||
Lambda.prototype._runHandler = function( handler, event ) { | ||
var context = { | ||
done: function( ) { | ||
process.exit(0); | ||
} | ||
} | ||
handler( event, context ); | ||
}; | ||
Lambda.prototype._zipfileTmpPath = function( functionName ) { | ||
var | ||
ms_since_epoch = +new Date, | ||
filename = functionName + "-" + ms_since_epoch + ".zip", | ||
zipfile = path.join( os.tmpDir(), filename ); | ||
return zipfile; | ||
}; | ||
Lambda.prototype._params = function( program, buffer ) { | ||
return params; | ||
}; | ||
Lambda.prototype.deploy = function( program ) { | ||
@@ -78,6 +32,6 @@ if (program.substr(-7) === '.lambda') | ||
aws.config.update({ | ||
accessKeyId: $config.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: $config.AWS_SECRET_ACCESS_KEY, | ||
accessKeyId: $config.AWS_KEY, | ||
secretAccessKey: $config.AWS_SECRET, | ||
region: $config.AWS_REGION | ||
}); | ||
}) | ||
@@ -88,3 +42,3 @@ $config.FunctionName = program.split('/').slice(-1)[0] | ||
var lambda = new aws.Lambda( { apiVersion: "2014-11-11" } ) | ||
var tmpfile = this._zipfileTmpPath( $config.FunctionName ) | ||
var tmpfile = path.join( os.tmpDir(), $config.FunctionName + "-" + new Date().getTime() + ".zip" ) | ||
var $configPath = program.split('/').slice(0,-1).join('/') | ||
@@ -91,0 +45,0 @@ //console.log( $configPath ) |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"homepage": "https://github.com/databank/aws-lambda", | ||
@@ -17,0 +17,0 @@ "bugs": "https://github.com/databank/aws-lambda/issues", |
@@ -19,92 +19,26 @@ # node-lambda | ||
## Example App | ||
The [node-lambda-template](https://github.com/RebelMail/node-lambda-template) example app makes it easy to get up and running. | ||
## Usage | ||
There are 3 available commands. | ||
``` | ||
lambda setup | ||
lambda run | ||
lambda deploy | ||
lambda deploy my-function.lambda | ||
``` | ||
### Commands | ||
## Configuration File | ||
#### setup | ||
Initializes the `event.json` and `.env` files. `event.json` is where you mock your event. `.env.` is where you place your deployment configuration. | ||
``` | ||
$ lambda setup --help | ||
// contents of my-function.lambda | ||
// PATH must point to the deploy folder | ||
// can be relative or absolute | ||
{ | ||
"PATH": "./test-function", | ||
"AWS_KEY": "your_key", | ||
"AWS_SECRET": "your_secret", | ||
"AWS_REGION": "us-east-1", | ||
Usage: run [options] | ||
Options: | ||
-h, --help output usage information | ||
"Role": "your_amazon_role", | ||
"Handler": "index.handler", | ||
"MemorySize": "128", | ||
"Timeout": "3", | ||
"Description": "" | ||
} | ||
``` | ||
After running setup, it's a good idea to gitignore the generated `event.json` and `.env` file. | ||
``` | ||
echo ".env\nevent.json" >> .gitignore | ||
``` | ||
#### run | ||
Runs your Amazon Lambda index.js file locally. Passes `event.json` data to the Amazon Lambda event object. | ||
``` | ||
$ lambda run --help | ||
Usage: run [options] | ||
Options: | ||
-h, --help output usage information | ||
-h, --handler [index.handler] Lambda Handler {index.handler} | ||
``` | ||
#### deploy | ||
Bundles and deploys your application up to Amazon Lambda. | ||
``` | ||
$ lambda deploy --help | ||
Usage: deploy [options] | ||
Options: | ||
-h, --help output usage information | ||
-e, --environment [staging] Choose environment {development, stating, production} | ||
-a, --accessKey [your_key] AWS Access Key | ||
-s, --secretKey [your_secret] AWS Secret Key | ||
-r, --region [us-east-1] AWS Region | ||
-n, --functionName [node-lambda] Lambda FunctionName | ||
-h, --handler [index.handler] Lambda Handler {index.handler} | ||
-m, --mode [event] Lambda Mode | ||
-o, --role [your_role] Amazon role | ||
-m, --memorySize [128] Lambda Memory Size | ||
-t, --timeout [3] Lambda Timeout | ||
-d, --description [missing] Lambda Description | ||
-u, --runtime [nodejs] Lambda Runtime | ||
``` | ||
## Contributing | ||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request | ||
## Running tests | ||
``` | ||
npm install | ||
npm test | ||
``` |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
2
6762
131
44