Socket
Socket
Sign inDemoInstall

grunt-aws-lambda

Package Overview
Dependencies
60
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

.travis.yml

41

Gruntfile.js

@@ -32,9 +32,7 @@ /*

// Configuration to be run (and then tested).
lambda: {
lambda_invoke: {
default_options: {
options: {
},
files: {
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123']
file_name: 'test/fixtures/index.js',
event: 'test/fixtures/event.json'
}

@@ -44,10 +42,30 @@ },

options: {
event: 'foo'
},
files: {
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123']
file_name: 'test/fixtures/custom_index.js',
event: 'test/fixtures/custom_event.json',
handler: 'myfunction'
}
}
},
lambda_package: {
default_options: {
options: {
dist_folder: 'tmp/dist',
package_folder: 'test/fixtures/package_default'
}
},
custom_options: {
options: {
dist_folder: 'tmp/dist',
include_time: false,
package_folder: 'test/fixtures/package_custom'
}
}
},
lambda_deploy: {
default_options: {
options: {
},
function: 'lambda-test'
}
},
// Unit tests.

@@ -69,7 +87,6 @@ nodeunit: {

// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'nodeunit']);
grunt.registerTask('test', ['clean', 'lambda_package', 'nodeunit']);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
};
{
"name": "grunt-aws-lambda",
"description": "A grunt plugin to help develop AWS Lambda functions.",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/Tim-B/grunt-aws-lambda",

@@ -34,2 +34,3 @@ "author": {

"rimraf": "~2.2.8",
"glob": "~4.3.0",
"aws-sdk": "~2.0.29"

@@ -41,3 +42,4 @@ },

"grunt-contrib-nodeunit": "^0.3.3",
"grunt": "~0.4.5"
"grunt": "~0.4.5",
"adm-zip": "~0.4.4"
},

@@ -44,0 +46,0 @@ "peerDependencies": {

@@ -5,2 +5,4 @@ # grunt-aws-lambda

[![Build Status](https://travis-ci.org/Tim-B/grunt-aws-lambda.svg)](https://travis-ci.org/Tim-B/grunt-aws-lambda)
This plugin provides helpers for:

@@ -87,7 +89,9 @@ * Running Lambda functions locally

grunt.initConfig({
lambda_invoke: {
options: {
// Task-specific options go here.
}
},
lambda_invoke: {
default: {
options: {
// Task-specific options go here.
}
}
},
});

@@ -123,5 +127,9 @@ ```

grunt.initConfig({
lambda_invoke: {
options: {}
},
lambda_invoke: {
default: {
options: {
// Task-specific options go here.
}
}
},
});

@@ -177,7 +185,9 @@ ```

grunt.initConfig({
lambda_package: {
options: {
// Task-specific options go here.
}
},
lambda_package: {
default: {
options: {
// Task-specific options go here.
}
}
},
});

@@ -188,8 +198,14 @@ ```

##### options.package_file
##### options.include_time
Type: `Boolean`
Default value: `true`
Whether or not to timestamp the packages, if set to true the current date/time will be included in the zip name, if false
then the package name will be constant and consist of just the package name and version.
##### options.package_folder
Type: `String`
Default value: `package.json`
Default value: `./`
Name of your npm package.json file, this is used to obtain version information and project name to intelligently
name package files.
The path to your npm package, must contain the package.json file.

@@ -209,5 +225,9 @@ ##### options.dist_folder

grunt.initConfig({
lambda_package: {
options: {}
},
lambda_package: {
default: {
options: {
// Task-specific options go here.
}
}
},
});

@@ -263,14 +283,14 @@ ```

The lambda_deploy task calls the `lambda_package` task then another task called 'lambda_upload'. Therefore configuration
values should be put under the `lambda_upload` section.
In your project's Gruntfile, add a section named `lambda_deploy` to the data object passed into `grunt.initConfig()`.
In your project's Gruntfile, add a section named `lambda_upload` to the data object passed into `grunt.initConfig()`.
```js
grunt.initConfig({
lambda_upload: {
options: {
// Task-specific options go here.
}
},
lambda_deploy: {
default: {
options: {
// Task-specific options go here.
},
function: 'my-lambda-function'
}
},
});

@@ -281,8 +301,39 @@ ```

##### options.function
##### function
Type: `String`
Default value: `lambda`
Default value: None - Required
The name of your target Lambda function, ie. the name of the function in the AWS console.
##### package
Type: `String`
Default value: Package name set by package task of same target - see below.
The name of the package to be uploaded.
When the lambda_package task runs it sets the package value for the lambda_deploy target with the same name.
Therefore if lambda_package and lambda_deploy have a target (eg. default) with the same name you will not
need to provide this value - it will be passed automatically.
For example, your Gruntfile.js might contain the following:
```js
grunt.initConfig({
lambda_deploy: {
default: {
function: 'my-lambda-function'
}
},
lambda_package: {
default: {
}
}
});
```
You could then run `grunt lambda_package lambda_deploy` and it'll automatically create the package and deploy it without
having to specify a package name.
##### options.profile

@@ -308,5 +359,7 @@ Type: `String`

grunt.initConfig({
lambda_deploy: {
options: {}
},
lambda_deploy: {
default: {
function: 'my-lambda-function'
}
}
});

@@ -318,2 +371,13 @@ ```

### Streamlining deploy
You can combine the lambda_package and lambda_deploy into a single deploy task by adding the following to your
Gruntfile.js:
```js
grunt.registerTask('deploy', ['lambda_package', 'lambda_deploy']);
```
You can then run `grunt deploy` to perform both these functions in one step.
### AWS credentials

@@ -380,1 +444,2 @@

* 0.1.0 - Initial release
* 0.2.0 - Adding some unit tests, refactoring deploy task into single task and converting tasks to multitasks

@@ -13,8 +13,56 @@ /*

var path = require('path');
var fs = require('fs');
var AWS = require('aws-sdk');
// Please see the Grunt documentation for more information regarding task
// creation: http://gruntjs.com/creating-tasks
grunt.registerTask('lambda_deploy', ['lambda_package', 'lambda_upload']);
grunt.registerMultiTask('lambda_deploy', 'Uploads a package to lambda', function () {
grunt.config.requires('lambda_deploy.' + this.target + '.function');
grunt.config.requires('lambda_deploy.' + this.target + '.package');
var options = this.options({
profile: null,
region: 'us-east-1'
});
if (options.profile !== null) {
var credentials = new AWS.SharedIniFileCredentials({profile: options.profile});
AWS.config.credentials = credentials;
}
var deploy_function = grunt.config.get('lambda_deploy.' + this.target + '.function');
var deploy_package = grunt.config.get('lambda_deploy.' + this.target + '.package');
AWS.config.update({region: options.region});
var done = this.async();
var lambda = new AWS.Lambda();
lambda.getFunction({FunctionName: deploy_function}, function (err, data) {
var current = data.Configuration;
var params = {
FunctionName: deploy_function,
Handler: current.Handler,
Mode: current.Mode,
Role: current.Role,
Runtime: current.Runtime
};
grunt.log.writeln('Uploading...');
fs.readFile(deploy_package, function (err, data) {
params['FunctionZip'] = data;
lambda.uploadFunction(params, function (err, data) {
grunt.log.writeln('Package deployed.');
done(true);
});
});
});
});
};

@@ -20,3 +20,3 @@ /*

grunt.registerTask('lambda_invoke', [], function () {
grunt.registerMultiTask('lambda_invoke', 'Invokes a lambda function for testing purposes', function () {

@@ -29,15 +29,16 @@ var options = this.options({

console.log("");
grunt.log.writeln("");
var done = this.async();
var context = {
done: function (status, message) {
var success = status === null;
console.log("");
console.log("Message");
console.log("-------");
console.log(message);
done(success)
grunt.log.writeln("");
grunt.log.writeln("Message");
grunt.log.writeln("-------");
grunt.log.writeln(message);
done(success);
}
}
};

@@ -44,0 +45,0 @@ var lambda = require(path.resolve(options.file_name));

@@ -24,10 +24,13 @@ /*

grunt.registerTask('lambda_package', [], function () {
grunt.registerMultiTask('lambda_package', 'Creates a package to be uploaded to lambda', function () {
var task = this;
var options = this.options({
'package_file': 'package.json',
'dist_folder': 'dist'
'dist_folder': 'dist',
'include_time': true,
'package_folder': './'
});
var pkg = grunt.file.readJSON(path.resolve(options.package_file));
var pkg = grunt.file.readJSON(path.resolve(options.package_folder + '/package.json'));

@@ -38,5 +41,8 @@ var dir = new tmp.Dir();

var now = new Date();
var time_string = now.getFullYear() + '-' + now.getMonth() + '-' + now.getDate()
+ '-' + now.getHours() + '-' + now.getMinutes() + '-' + now.getSeconds();
var time_string = 'latest';
if (options.include_time) {
time_string = now.getFullYear() + '-' + now.getMonth() + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes() + '-' + now.getSeconds();
}
var file_version = pkg.version.replace(/\./g, '-');

@@ -52,3 +58,3 @@ var archive_name = pkg.name + '_' + file_version + '_' + time_string;

npm.commands.install(install_location, "./", function () {
npm.commands.install(install_location, options.package_folder, function () {

@@ -76,6 +82,7 @@ var output = fs.createWriteStream(install_location + '/' + archive_name + '.zip');

rimraf(install_location, function () {
grunt.config.set('lambda_deploy.latest_package',
grunt.config.set('lambda_deploy.' + task.target + '.package',
'./' + options.dist_folder + '/' + archive_name + '.zip');
grunt.log.writeln('Created package at ' + options.dist_folder + '/' + archive_name + '.zip')
grunt.log.writeln('Created package at ' + options.dist_folder + '/' + archive_name + '.zip');
done(true);

@@ -85,4 +92,4 @@ });

});
})
})
});
});

@@ -89,0 +96,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc