Skip to content

Commit cc92fea

Browse files
authored
Merge pull request #43 from ashiina/develop
1.1.0 release
2 parents b890420 + cc1a639 commit cc92fea

File tree

14 files changed

+543
-225
lines changed

14 files changed

+543
-225
lines changed

.jshintrc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"passfail" : false,
3+
"maxerr" : 50,
4+
"browser" : true,
5+
"browserify" : false,
6+
"couch" : false,
7+
"devel" : true,
8+
"dojo" : false,
9+
"jasmine" : false,
10+
"jquery" : false,
11+
"mocha" : true,
12+
"mootools" : false,
13+
"node" : true,
14+
"nonstandard" : false,
15+
"phantom" : false,
16+
"prototypejs" : false,
17+
"qunit" : false,
18+
"rhino" : false,
19+
"shelljs" : false,
20+
"typed" : false,
21+
"worker" : false,
22+
"wsh" : false,
23+
"yui" : false,
24+
"debug" : false,
25+
"devel" : false,
26+
"bitwise" : true,
27+
"camelcase" : true,
28+
"curly" : true,
29+
"eqeqeq" : true,
30+
"forin" : false,
31+
"freeze" : true,
32+
"immed" : true,
33+
"indent" : 2,
34+
"latedef" : true,
35+
"laxbreak" : false,
36+
"loopfunc" : false,
37+
"maxparams" : 5,
38+
"maxdepth" : 5,
39+
"maxstatements" : 100,
40+
"maxcomplexity" : false,
41+
"maxlen" : 100,
42+
"newcap" : true,
43+
"noarg" : true,
44+
"noempty" : true,
45+
"nonbsp" : true,
46+
"nonew" : true,
47+
"plusplus" : false,
48+
"quotmark" : true,
49+
"strict" : true,
50+
"undef" : true,
51+
"unused" : "strict",
52+
"asi" : false,
53+
"boss" : false,
54+
"eqnull" : false,
55+
"esversion" : 6,
56+
"moz" : false,
57+
"evil" : false,
58+
"expr" : false,
59+
"funcscope" : false,
60+
"globalstrict" : false,
61+
"iterator" : false,
62+
"lastsemic" : false,
63+
"laxbreak" : false,
64+
"laxcomma" : false,
65+
"loopfunc" : false,
66+
"multistr" : false,
67+
"noyield" : false,
68+
"notypeof" : false,
69+
"proto" : false,
70+
"scripturl" : false,
71+
"shadow" : false,
72+
"sub" : true,
73+
"supernew" : false,
74+
"validthis" : false,
75+
"globals" : {}
76+
}

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: node_js
2+
node_js:
3+
- "1.8"
4+
- "2.5"
5+
- "3.3"
6+
- "4.4"
7+
sudo: false
8+
#cache:
9+
# directories:
10+
# - node_modules
11+
script:
12+
- "cd test && ../node_modules/mocha/bin/mocha"
13+

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ChangeLog
22

3+
## 1.0.0 (2016/6/xx)
4+
* lambda-local can now be imported as a node module, and be executed from other node.js programs
5+
36
## 0.0.10 (2016/5/29)
47
* Support for Node.js 4.3.2 runtime
58
* Added feature to import AWS profile from commandline option

README.md

Lines changed: 78 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,111 @@
1-
Lambda-local
2-
============
1+
# Lambda-local
32

4-
Lambda-local lets you test Amazon Lambda functions on your local machine with sample event data.
5-
The `context` of the Lambda function is already loaded so you do not have to worry about it.
6-
You can pass any `event` JSON object as you please.
3+
[![Build Status](https://travis-ci.org/ashiina/lambda-local.svg?branch=develop)](https://travis-ci.org/ashiina/lambda-local)
74

5+
Lambda-local lets you test Amazon Lambda functions on your local machine with sample event data.
6+
The `context` of the Lambda function is already loaded so you do not have to worry about it.
7+
You can pass any `event` JSON object as you please.
8+
9+
## Install
810

9-
Install
10-
----
1111
```bash
1212
npm install -g lambda-local
1313
```
1414

15+
## Usage
16+
17+
### As a command line tool
1518

16-
Usage
17-
-----
19+
You can use Lambda-local as a command line tool.
1820

1921
```bash
2022
# Usage
21-
lambda-local -l index.js -h handler -e event-samples/s3-put.js
23+
lambda-local -l index.js -h handler -e event-samples/s3-put.js
2224
```
2325

24-
About
25-
-----
26+
### In another node.js script
27+
28+
You can also use Lambda local directly in a script. For instance, it is interesting in a [mocha][1] test suite in combination with [istanbull][2] in order to get test coverage.
29+
30+
```js
31+
const lambdaLocal = require('lambda-local');
32+
33+
var jsonPayload = {
34+
'key1': 'value1',
35+
'key2': 'value2',
36+
'key3': 'value3'
37+
}
38+
39+
lambdaLocal.execute({
40+
event: jsonPayload,
41+
lambdaPath: path.join(__dirname, 'path/to/index.js'),
42+
profilePath: '~/.aws/credentials',
43+
profileName: 'default',
44+
timeoutMs: 3000,
45+
callback: function(err, data) {
46+
if (err) {
47+
console.log(err);
48+
} else {
49+
console.log(data);
50+
}
51+
}
52+
});
53+
```
54+
55+
## About
56+
2657
### Command
27-
* -l, --lambdapath [lambda file name] Specify Lambda function file name.
28-
* -e, --eventpath [event data file name] Specify event data file name.
29-
* -h, --handler [lambda-function handler name (optional)] Lambda function handler name. Default is "handler".
30-
* -t, --timeout [timeout seconds (optional)] Seconds until lambda function timeout. Default is 3 seconds.
31-
* -c, --callbackforce (optional) Force the function to stop after having called context.done/succeed/fail.
32-
* -p, --profile [aws file path (optional)] Read the AWS profile to get the credidentials.
58+
* -l, --lambda-path <lambda index path> (required) Specify Lambda function file name.
59+
* -e, --event-path <event path> (required) Specify event data file name.
60+
* -h, --handler <handler name> (optional) Lambda function handler name. Default is "handler".
61+
* -t, --timeout <timeout> (optional) Seconds until lambda function timeout. Default is 3 seconds.
62+
* -n, --no-force-callback (optional) Force the function to stop after having called the handler function even if context.done/succeed/fail was not called.
63+
* -p, --profile <aws profile name> (optional) Read the AWS profile to get the credentials from file name.
64+
* -p, --profile-path <aws profile name> (optional) Read the specified AWS credentials file.
3365

3466
### Event data
35-
Event sample data are placed in `event-samples` folder - feel free to use the files in here, or create your own event data.
36-
Event data are just JSON objects exported:
67+
Event sample data are placed in `event-samples` folder - feel free to use the files in here, or create your own event data.
68+
Event data are just JSON objects exported:
3769

3870
```js
39-
# Sample event data
71+
// Sample event data
4072
module.exports = {
4173
foo: "bar"
4274
};
4375
```
4476

4577
### Context
46-
The `context` object has been directly extracted from the source visible when running an actual Lambda function on AWS.
47-
They may change the internals of this object, and Lambda-local does not guarantee that this will always be up-to-date with the actual context object.
78+
The `context` object has been directly extracted from the source visible when running an actual Lambda function on AWS.
79+
They may change the internals of this object, and Lambda-local does not guarantee that this will always be up-to-date with the actual context object.
4880

4981
### AWS-SDK
5082
Since the Amazon Lambda can load the AWS-SDK npm without installation, Lambda-local has also packaged AWS-SDK in its dependencies.
5183
If you want to use this, please use the "-p" option with the aws credentials file. More infos here:
5284
http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files
5385

54-
License
55-
----------
86+
## API
87+
88+
### LambdLocal
89+
90+
#### `execute(options)`
91+
92+
Executes a lambda given the `options` object where keys are:
93+
- `event` - requested event as a json object,
94+
- `lambdaPath` - requested path to the lambda function,
95+
- `profilePath` - optional path to your AWS credentials file
96+
- `profileName` - optional aws profile name
97+
- `lambdaHandler` - optional handler name, default to `handler`
98+
- `region` - optional AWS region, default to `us-east-1`
99+
- `callbackWaitsForEmptyEventLoop` - optional, default to `true` which forces the function to stop after having called the handler function even if context.done/succeed/fail was not called.
100+
- `timeoutMs` - optional timeout, default to 3000 ms
101+
- `mute` - optional, allows to mute console.log calls in the lambda function, default false
102+
- `callback` - optional lambda third parameter [callback][3]
103+
104+
## License
105+
56106
This library is released under the MIT license.
57107

108+
[1]: https://mochajs.org/
109+
[2]: http://gotwarlost.github.io/istanbul/
110+
[3]: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
58111

0 commit comments

Comments
 (0)