Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
55f9787
Added package command to create a local zip.
Dec 18, 2015
cff0118
added test for refactored _archive method.
Feb 3, 2016
fc1a353
Add -e to not escape \n when echo'ing
justinmchase Feb 25, 2016
5ea4782
VpcConfig support:
DeviaVir Mar 25, 2016
a8e27ca
Use AWS API 2015-03-31:
DeviaVir Mar 25, 2016
ae69e4a
Merge pull request #64 from DeviaVir/vpc-config-support
DeviaVir Apr 8, 2016
55a3c92
Merge pull request #58 from justinmchase/patch-1
DeviaVir Apr 8, 2016
e46dc0b
Merge remote-tracking branch upstream/master into kecaps-master
Apr 8, 2016
ae1826d
Merge pull request #2 from DeviaVir/kecaps-master
kecaps Apr 8, 2016
f9b36cf
Merge pull request #56 from kecaps/master
DeviaVir Apr 9, 2016
9795df6
Only ignore deploy.env by default
Apr 9, 2016
56d5843
Merge pull request #69 from DeviaVir/ignore_deploy_env_only
DeviaVir Apr 9, 2016
e355a11
Updated readme: MODE is no longer a thing
DeviaVir Apr 11, 2016
7f6da59
Merge pull request #71 from motdotla/mode_readme
DeviaVir Apr 11, 2016
60aa062
Throw on failures
DeviaVir Apr 11, 2016
fec0bf3
Merge pull request #72 from motdotla/throw
DeviaVir Apr 11, 2016
3c8058e
- Fix rsync namespaced error
Apr 11, 2016
e9db472
Merge pull request #73 from DeviaVir/namespaced
DeviaVir Apr 11, 2016
883aa60
Update to pass callback for nodejs4.3 runtime (#74)
briandonahue Apr 12, 2016
cf08e28
Runhandler: Hotfixes
Apr 12, 2016
fadef8b
Runhandler: Hotfixes (#75)
DeviaVir Apr 12, 2016
b337042
Post install script second atttempt
navihtot Apr 14, 2016
cc48902
Merge remote-tracking branch 'upstream/master'
Apr 15, 2016
210687b
Add '-x' / '--excludeGlobs' args for general file exclusion on deploy…
DeviaVir Apr 18, 2016
07b2edc
Merge remote-tracking branch 'upstream/master'
Apr 18, 2016
3a0cb1d
Excludes: Ignore *.swp (#81)
DeviaVir Apr 18, 2016
1702fa4
Add option to create a sample file with a custom filename and fix the…
pedrocarrico Apr 18, 2016
13ea71d
Merge remote-tracking branch 'upstream/master'
Apr 18, 2016
f1a8a22
Feature/context file (#82)
DeviaVir Apr 18, 2016
2671fd5
Merge remote-tracking branch 'upstream/master'
Apr 18, 2016
aae2e98
Merge branch 'sm-adjustments' of https://github.com/motdotla/node-lam…
Apr 18, 2016
42f6705
Update changelog
Apr 18, 2016
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
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.8.0] - 2016-01-20
## [0.8.0] - 2016-04-18
### Added
- CHANGELOG to ["make it easier for users and contributors to see precisely what notable changes have been made between each release"](http://keepachangelog.com/). Linked to from README
- LICENSE to be more explicit about what was defined in `package.json`. Linked to from README
- it is OK to not set default value for AWS Credentials
- It is OK to not set default value for AWS Credentials so AWS can use Roles and internally set AWS credentials
- Added `context.json` so it can easily be overwritten
- Allow using a custom (and passed through) `event.json` file
- Added `package` command for easy zip creation and inspection
- Added `VpcConfig` support, see [this PR](https://github.com/motdotla/node-lambda/pull/64) for more information
- Updated the AWS API version used to `2015-03-31`
- Make sure we throw errors on unrecoverable failures so other programs can listen on that
- Added support for nodejs4.3 runtime ([introducted to AWS](https://aws.amazon.com/blogs/compute/node-js-4-3-2-runtime-now-available-on-lambda/) Apr 7 2016)
- Added support for `post install scripts`, this `post_install.sh` file will be triggered after `npm install --production` in case you want to run any code on your application before zipping
- Added `-x` / `--excludeGlobs` to allow custom file exclusion
- Excluding `*.swp`, `deploy.env` by default now
50 changes: 42 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ There are 3 available commands.
```
node-lambda setup
node-lambda run
node-lambda package
node-lambda deploy
```

### Commands

#### setup

Initializes the `event.json`, `.env` files, and `deploy.env` files. `event.json` is where you mock your event. `.env` is where you place your deployment configuration. `deploy.env` has the same format as `.env`, but is used for holding any environment/config variables that you need to be deployed with your code to Lambda but you don't want in version control (e.g. DB connection info).
Initializes the `event.json`, `context.json`, `.env` files, and `deploy.env` files. `event.json` is where you mock your event. `context.json` is where you can add additional mock data to the context passed to your lambda function. `.env` is where you place your deployment configuration. `deploy.env` has the same format as `.env`, but is used for holding any environment/config variables that you need to be deployed with your code to Lambda but you don't want in version control (e.g. DB connection info).

```
$ node-lambda setup --help
Expand All @@ -50,7 +51,7 @@ $ node-lambda setup --help
After running setup, it's a good idea to gitignore the generated `event.json` and `.env` files.

```
echo ".env\ndeploy.env\nevent.json" >> .gitignore
echo -e ".env\ndeploy.env\nevent.json" >> .gitignore
```

#### run
Expand All @@ -64,9 +65,29 @@ $ node-lambda run --help

Options:

-h, --help output usage information
-h, --handler [index.handler] Lambda Handler {index.handler}
-j, --eventFile [event.json] Event JSON File
-h, --help Output usage information
--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
-x, --contextFile [context.json] Context JSON file
```

#### package

Bundles your application into a local zip file.

```
$ node-lambda package --help

Usage: package [options]

Options:

-h, --help output usage information
-p, --packageDirectory [build] Local Package Directory
-n, --functionName [node-lambda] Lambda FunctionName
-e, --environment [staging] Choose environment {development, staging, production}
-f, --configFile [] Path to file holding secret environment variables (e.g. "deploy.env")
```

#### deploy
Expand All @@ -87,21 +108,34 @@ $ node-lambda deploy --help
-k, --sessionToken [your_token] AWS Session Token
-r, --region [us-east-1] AWS Region(s)
-n, --functionName [node-lambda] Lambda FunctionName
-h, --handler [index.handler] Lambda Handler {index.handler}
-c, --mode [event] Lambda Mode
--handler [index.handler] Lambda Handler {index.handler}
-o, --role [your_role] Amazon Role ARN
-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")`
-b, --vpcSubnets [] VPC Subnet ID(s, comma separated list) for your Lambda Function, when using this, the below param is also required
-g, --vpcSecurityGroups [] VPC Security Group ID(s, comma separated list) for your Lambda Function, when using this, the above param is also required
```

## Custom Environment Variables

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.

## Post install script
When running `node-lambda deploy` if you need to do some action after `npm install --production` and before deploying to AWS Lambda (i.e. replace some modules with precompiled ones or download some libraries) you can create `post_install.sh` script. If the file exists the script will be executed (and output shown after execution) if not it is skipped. Make sure that the script is executable.

## Other AWS Lambda Tools Projects

+ [lambdaws](https://github.com/mentum/lambdaws)
Expand Down
37 changes: 32 additions & 5 deletions bin/node-lambda
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ dotenv.load();

var AWS_ENVIRONMENT = process.env.AWS_ENVIRONMENT || '';
var CONFIG_FILE = process.env.CONFIG_FILE || '';
var EXCLUDE_GLOBS = process.env.EXCLUDE_GLOBS || '';
var AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
var AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
var AWS_SESSION_TOKEN = process.env.AWS_SESSION_TOKEN || '';
var AWS_REGION = process.env.AWS_REGION || 'us-east-1,us-west-2,eu-west-1';
var AWS_FUNCTION_NAME = process.env.AWS_FUNCTION_NAME || packageJson.name;
var AWS_HANDLER = process.env.AWS_HANDLER || 'index.handler';
var AWS_MODE = 'event';
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 || '';
var AWS_VPC_SECURITY_GROUPS = process.env.AWS_VPC_SECURITY_GROUPS || '';
var EVENT_FILE = process.env.EVENT_FILE || 'event.json';
var PACKAGE_DIRECTORY = process.env.PACKAGE_DIRECTORY;
var CONTEXT_FILE = process.env.CONTEXT_FILE || 'context.json';

program
.version(lambda.version)
Expand All @@ -35,26 +40,48 @@ program
.option('-k, --sessionToken [' + AWS_SESSION_TOKEN + ']', 'AWS Session Token', AWS_SESSION_TOKEN)
.option('-r, --region [' + AWS_REGION + ']', 'AWS Region', AWS_REGION)
.option('-n, --functionName [' + AWS_FUNCTION_NAME + ']', 'Lambda FunctionName', AWS_FUNCTION_NAME)
.option('-h, --handler [' + AWS_HANDLER + ']', 'Lambda Handler {index.handler}', AWS_HANDLER)
.option('-c, --mode [' + AWS_MODE + ']', 'Lambda Mode', AWS_MODE)
.option('--handler [' + AWS_HANDLER + ']', 'Lambda Handler {index.handler}', AWS_HANDLER)
.option('-o, --role [' + AWS_ROLE + ']', 'Amazon Role ARN', AWS_ROLE)
.option('-m, --memorySize [' + AWS_MEMORY_SIZE + ']', 'Lambda Memory Size', AWS_MEMORY_SIZE)
.option('-t, --timeout [' + AWS_TIMEOUT + ']', 'Lambda Timeout', AWS_TIMEOUT)
.option('-d, --description [' + AWS_DESCRIPTION + ']', 'Lambda Description', AWS_DESCRIPTION)
.option('-u, --runtime [' + AWS_RUNTIME + ']', 'Lambda Runtime', AWS_RUNTIME)
.option('-p, --publish [' + AWS_PUBLISH + ']', 'Lambda Publish', AWS_PUBLISH)
.option('-v, --version [' + AWS_FUNCTION_VERSION + ']', 'Lambda Function Version', AWS_FUNCTION_VERSION)
.option('-b, --vpcSubnets [' + AWS_VPC_SUBNETS + ']', 'Lambda Function VPC Subnets', AWS_VPC_SUBNETS)
.option('-g, --vpcSecurityGroups [' + AWS_VPC_SECURITY_GROUPS + ']', 'Lambda VPC Security Group',
AWS_VPC_SECURITY_GROUPS)
.option('-p, --packageDirectory [' + PACKAGE_DIRECTORY + ']', 'Local Package Directory', PACKAGE_DIRECTORY)
.option('-f, --configFile [' + CONFIG_FILE + ']',
'Path to file holding secret environment variables (e.g. "deploy.env")', CONFIG_FILE)
.option('-x, --excludeGlobs [' + EXCLUDE_GLOBS + ']',
'Space-separated glob pattern(s) for additional exclude files (e.g. "event.json dotenv.sample")', EXCLUDE_GLOBS)
.action(function (prg) {
lambda.deploy(prg);
});

program
.version(lambda.version)
.command('package')
.description('Create zipped package for Amazon Lambda deployment')
.option('-p, --packageDirectory [' + PACKAGE_DIRECTORY + ']', 'Local Package Directory', PACKAGE_DIRECTORY)
.option('-n, --functionName [' + AWS_FUNCTION_NAME + ']', 'Lambda FunctionName', AWS_FUNCTION_NAME)
.option('-e, --environment [' + AWS_ENVIRONMENT + ']', 'Choose environment {dev, staging, production}',
AWS_ENVIRONMENT)
.option('-f, --configFile [' + CONFIG_FILE + ']',
'Path to file holding secret environment variables (e.g. "deploy.env")', CONFIG_FILE)
.action(function (prg) {
lambda.package(prg);
});

program
.version(lambda.version)
.command('run')
.description('Run your Amazon Lambda application locally')
.option('-h, --handler [' + AWS_HANDLER + ']', 'Lambda Handler {index.handler}', AWS_HANDLER)
.option('--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)
.option('-x, --contextFile [' + CONTEXT_FILE + ']', 'Context JSON File', CONTEXT_FILE)
.action(function (prg) {
lambda.run(prg);
});
Expand Down
4 changes: 4 additions & 0 deletions lib/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ AWS_MEMORY_SIZE=128
AWS_TIMEOUT=3
AWS_DESCRIPTION=
AWS_RUNTIME=nodejs
AWS_VPC_SUBNETS=
AWS_VPC_SECURITY_GROUPS=
EXCLUDE_GLOBS="event.json"
PACKAGE_DIRECTORY=build
1 change: 1 addition & 0 deletions lib/context.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading