Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-lambda-helper

Package Overview
Dependencies
Maintainers
4
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-lambda-helper - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

coverage/lcov-report/base.css

2

coverage/coverage.json

@@ -1,1 +0,1 @@

{"/home/jimmy/repo/aws-lambda-helper/lib/index.js":{"path":"/home/jimmy/repo/aws-lambda-helper/lib/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":3,"8":1,"9":2,"10":2,"11":2,"12":1,"13":1,"14":1,"15":2,"16":2,"17":1,"18":1,"19":1,"20":1},"b":{"1":[0,1],"2":[1,1],"3":[1,2],"4":[1,1],"5":[1,1]},"f":{"1":1,"2":3,"3":2},"fnMap":{"1":{"name":"_interopRequireDefault","line":0,"loc":{"start":{"line":0,"column":0},"end":{"line":0,"column":0}},"skip":true},"2":{"name":"getEnvironment","line":5,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":38}}},"3":{"name":"validateWithSchema","line":15,"loc":{"start":{"line":15,"column":0},"end":{"line":15,"column":55}}}},"statementMap":{"1":{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},"2":{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},"3":{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},"4":{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},"5":{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},"6":{"start":{"line":5,"column":0},"end":{"line":5,"column":0}},"7":{"start":{"line":6,"column":6},"end":{"line":6,"column":2}},"8":{"start":{"line":6,"column":53},"end":{"line":6,"column":2}},"9":{"start":{"line":8,"column":6},"end":{"line":5,"column":38}},"10":{"start":{"line":9,"column":6},"end":{"line":5,"column":38}},"11":{"start":{"line":11,"column":6},"end":{"line":11,"column":2}},"12":{"start":{"line":11,"column":18},"end":{"line":11,"column":2}},"13":{"start":{"line":12,"column":5},"end":{"line":5,"column":38}},"14":{"start":{"line":15,"column":0},"end":{"line":15,"column":0}},"15":{"start":{"line":16,"column":6},"end":{"line":15,"column":55}},"16":{"start":{"line":17,"column":6},"end":{"line":17,"column":2}},"17":{"start":{"line":17,"column":25},"end":{"line":17,"column":2}},"18":{"start":{"line":18,"column":5},"end":{"line":15,"column":55}},"19":{"start":{"line":21,"column":15},"end":{"line":null,"column":null}},"20":{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true}},"branchMap":{"1":{"line":0,"type":"cond-expr","locations":[{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true}]},"2":{"line":0,"type":"binary-expr","locations":[{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true},{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"skip":true}]},"3":{"line":6,"type":"if","locations":[{"start":{"line":6,"column":6},"end":{"line":6,"column":6}},{"start":{"line":6,"column":6},"end":{"line":6,"column":6}}]},"4":{"line":11,"type":"if","locations":[{"start":{"line":11,"column":6},"end":{"line":11,"column":6}},{"start":{"line":11,"column":6},"end":{"line":11,"column":6}}]},"5":{"line":17,"type":"if","locations":[{"start":{"line":17,"column":6},"end":{"line":17,"column":6}},{"start":{"line":17,"column":6},"end":{"line":17,"column":6}}]}}}}
{"/Users/Admin/work/aws-lambda-helper/lib/index.js":{"path":"/Users/Admin/work/aws-lambda-helper/lib/index.js","s":{"1":1,"2":1,"3":5,"4":5,"5":2,"6":2,"7":2,"8":2,"9":3,"10":2,"11":2,"12":2,"13":2,"14":1,"15":1,"16":3,"17":3,"18":3,"19":3,"20":3,"21":1,"22":3,"23":1,"24":2,"25":1,"26":1,"27":1,"28":1,"29":2,"30":1,"31":1,"32":1,"33":1,"34":1,"35":1,"36":1,"37":1},"b":{"1":[2,3],"2":[2,1],"3":[3,1],"4":[1,2],"5":[3,3],"6":[2,2],"7":[1,1],"8":[2,1],"9":[1,1],"10":[1,1],"11":[1,1]},"f":{"1":5,"2":3,"3":3,"4":2},"fnMap":{"1":{"name":"extractParams","line":5,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":44}}},"2":{"name":"AwsHelper","line":28,"loc":{"start":{"line":28,"column":0},"end":{"line":28,"column":42}}},"3":{"name":"getEnvironment","line":36,"loc":{"start":{"line":36,"column":0},"end":{"line":36,"column":34}}},"4":{"name":"(anonymous_4)","line":48,"loc":{"start":{"line":48,"column":16},"end":{"line":48,"column":38}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":3,"column":11}},"2":{"start":{"line":5,"column":0},"end":{"line":25,"column":1}},"3":{"start":{"line":7,"column":2},"end":{"line":7,"column":62}},"4":{"start":{"line":10,"column":2},"end":{"line":15,"column":3}},"5":{"start":{"line":11,"column":4},"end":{"line":11,"column":42}},"6":{"start":{"line":12,"column":4},"end":{"line":12,"column":43}},"7":{"start":{"line":13,"column":4},"end":{"line":13,"column":26}},"8":{"start":{"line":14,"column":4},"end":{"line":14,"column":13}},"9":{"start":{"line":17,"column":2},"end":{"line":22,"column":3}},"10":{"start":{"line":18,"column":4},"end":{"line":18,"column":42}},"11":{"start":{"line":19,"column":4},"end":{"line":19,"column":43}},"12":{"start":{"line":20,"column":4},"end":{"line":20,"column":51}},"13":{"start":{"line":21,"column":4},"end":{"line":21,"column":13}},"14":{"start":{"line":24,"column":2},"end":{"line":24,"column":81}},"15":{"start":{"line":28,"column":0},"end":{"line":34,"column":1}},"16":{"start":{"line":29,"column":2},"end":{"line":29,"column":15}},"17":{"start":{"line":30,"column":2},"end":{"line":30,"column":23}},"18":{"start":{"line":31,"column":2},"end":{"line":31,"column":27}},"19":{"start":{"line":32,"column":2},"end":{"line":32,"column":44}},"20":{"start":{"line":33,"column":2},"end":{"line":33,"column":11}},"21":{"start":{"line":36,"column":0},"end":{"line":42,"column":1}},"22":{"start":{"line":37,"column":2},"end":{"line":39,"column":3}},"23":{"start":{"line":38,"column":4},"end":{"line":38,"column":16}},"24":{"start":{"line":40,"column":2},"end":{"line":40,"column":67}},"25":{"start":{"line":41,"column":2},"end":{"line":41,"column":13}},"26":{"start":{"line":44,"column":0},"end":{"line":44,"column":29}},"27":{"start":{"line":46,"column":0},"end":{"line":46,"column":16}},"28":{"start":{"line":48,"column":0},"end":{"line":62,"column":2}},"29":{"start":{"line":49,"column":2},"end":{"line":51,"column":3}},"30":{"start":{"line":50,"column":4},"end":{"line":50,"column":55}},"31":{"start":{"line":52,"column":2},"end":{"line":52,"column":31}},"32":{"start":{"line":53,"column":2},"end":{"line":53,"column":32}},"33":{"start":{"line":54,"column":2},"end":{"line":60,"column":4}},"34":{"start":{"line":61,"column":2},"end":{"line":61,"column":30}},"35":{"start":{"line":63,"column":0},"end":{"line":63,"column":27}},"36":{"start":{"line":64,"column":0},"end":{"line":64,"column":31}},"37":{"start":{"line":65,"column":0},"end":{"line":65,"column":47}}},"branchMap":{"1":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":2},"end":{"line":10,"column":2}},{"start":{"line":10,"column":2},"end":{"line":10,"column":2}}]},"2":{"line":17,"type":"if","locations":[{"start":{"line":17,"column":2},"end":{"line":17,"column":2}},{"start":{"line":17,"column":2},"end":{"line":17,"column":2}}]},"3":{"line":31,"type":"binary-expr","locations":[{"start":{"line":31,"column":14},"end":{"line":31,"column":20}},{"start":{"line":31,"column":24},"end":{"line":31,"column":26}}]},"4":{"line":37,"type":"if","locations":[{"start":{"line":37,"column":2},"end":{"line":37,"column":2}},{"start":{"line":37,"column":2},"end":{"line":37,"column":2}}]},"5":{"line":37,"type":"binary-expr","locations":[{"start":{"line":37,"column":6},"end":{"line":37,"column":14}},{"start":{"line":37,"column":18},"end":{"line":37,"column":45}}]},"6":{"line":40,"type":"binary-expr","locations":[{"start":{"line":40,"column":12},"end":{"line":40,"column":17}},{"start":{"line":40,"column":21},"end":{"line":40,"column":66}}]},"7":{"line":49,"type":"if","locations":[{"start":{"line":49,"column":2},"end":{"line":49,"column":2}},{"start":{"line":49,"column":2},"end":{"line":49,"column":2}}]},"8":{"line":49,"type":"binary-expr","locations":[{"start":{"line":49,"column":6},"end":{"line":49,"column":13}},{"start":{"line":49,"column":17},"end":{"line":49,"column":37}}]},"9":{"line":56,"type":"binary-expr","locations":[{"start":{"line":56,"column":20},"end":{"line":56,"column":50}},{"start":{"line":56,"column":54},"end":{"line":56,"column":71}}]},"10":{"line":58,"type":"binary-expr","locations":[{"start":{"line":58,"column":15},"end":{"line":58,"column":31}},{"start":{"line":58,"column":35},"end":{"line":58,"column":44}}]},"11":{"line":59,"type":"binary-expr","locations":[{"start":{"line":59,"column":13},"end":{"line":59,"column":43}},{"start":{"line":59,"column":47},"end":{"line":59,"column":53}}]}}}}
{
"name": "aws-lambda-helper",
"version": "1.0.3",
"version": "2.0.0",
"description": "Collection of helper methods for lambda",
"main": "src/index.js",
"scripts": {
"nocov": "node ./node_modules/.bin/mocha --compilers js:babel-register test/*/*.js",
"nocov": "node ./node_modules/.bin/mocha test/*/*.js",
"test": "npm run lint && npm run coverage",
"coverage": "./node_modules/.bin/babel-node ./node_modules/.bin/babel-istanbul cover ./node_modules/.bin/_mocha test/*/*.js --report lcovonly -- -R spec",
"lint": "eslint --fix *.js **/*.js **/test/**/*.js",
"compile": "babel lib --out-dir src",
"prepublish": "npm run compile"
"coverage": "node ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha test/*/*.js --report lcov -- -R spec",
"lint": "node ./node_modules/eslint/bin/eslint.js --fix *.js **/*.js **/test/**/*.js"
},

@@ -21,15 +19,11 @@ "repository": {

"devDependencies": {
"babel-cli": "^6.4.5",
"babel-istanbul": "^0.6.0",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-transform-runtime": "^6.4.3",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"aws-sdk-mock": "^1.0.9",
"eslint": "^1.10.3",
"eslint-config-semistandard": "^5.0.0",
"istanbul": "^0.4.2",
"mocha": "^2.4.5"
},
"dependencies": {
"tv4": "^1.2.7"
"aws-sdk": "^2.2.40"
}
}
# aws-lambda-helper
Collection of helper methods for lambda
[![Build Status](https://travis-ci.org/tcdl/aws-lambda-helper.svg?branch=master)](https://travis-ci.org/tcdl/aws-lambda-helper)
[![codecov.io](https://codecov.io/github/tcdl/aws-lambda-helper/coverage.svg?branch=master)](https://codecov.io/github/tcdl/aws-lambda-helper?branch=master)

@@ -9,3 +11,3 @@ ## Installation

## Usage
`const helper = require('aws-lambda-helper');`
`var helper = require('aws-lambda-helper');`

@@ -20,3 +22,3 @@

```javascript
const context = {
var context = {
invokedFunctionArn: 'arn:123:abs:prod'

@@ -38,3 +40,3 @@ };

const data = {
var data = {
a: 1,

@@ -41,0 +43,0 @@ b: 'Hello World'

'use strict';
import assert from 'assert';
import helper from '../../lib';
import payloadSchema from '../fixtures/validationSchema';
var assert = require('assert');
var AwsHelper = require('./../../lib/index');
var awsMock = require('aws-sdk-mock');
describe('AWS Lambda helper', () => {
describe('validateWithSchema', () => {
it('should throw error for invalid data', (done) => {
const invalidData = {
body: {
docs: [{
param1: 'value1',
param2: ['123', '456'],
param3: 'standard'
}]
}
describe('AWS Lambda helper', function () {
describe('getEnvironment', function () {
it('should throw error when invokedFunctionArn is invalid', function (done) {
var badContext = {
invokedFunctionArn: 'arn:123:abs:prod'
};
try {
let result = helper.validateWithSchema(invalidData, payloadSchema);
done(result);
} catch (error) {
assert.equal(error.message, 'Missing required property: param4');
AwsHelper.getEnvironment(badContext);
} catch (e) {
var expected_err_msg = 'Error: Unexpected invokedFunctionArn format';
assert(e.toString().indexOf(expected_err_msg) > -1);
done();

@@ -29,49 +22,72 @@ }

it('should return true for valid data', (done) => {
const validData = {
body: {
docs: [{
param1: 'value1',
param2: ['123', '456'],
param3: 'standard',
param4: 5
}]
}
it('should return null if invokedFunctionArn is not set in context', function (done) {
var env = AwsHelper.getEnvironment({});
assert.equal(env, null);
done();
});
it('a valid ARN without environment should not set the env property', function (done) {
var context = {
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:mylambda'
};
let result = helper.validateWithSchema(validData, payloadSchema);
assert.equal(result, true);
var env = AwsHelper.getEnvironment(context);
assert.equal(env, null);
done();
});
});
describe('getEnvironment', () => {
it('should get environment variable from context', (done) => {
const context = {
invokedFunctionArn: 'arn:123:abs:prod'
it('should get environment variable from context', function (done) {
var context = {
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda:prod'
};
let env = helper.getEnvironment(context);
assert.equal(env, 'prod');
var awsHelper = AwsHelper(awsMock, context, {});
assert.equal(awsHelper.env, 'prod');
done();
});
it('should return null if invokedFunctionArn does not exist in context', (done) => {
let env = helper.getEnvironment({});
assert.equal(env, null);
it('config should be set to an empty object if undefined', function (done) {
var context = {
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda:prod'
};
var awsHelper = AwsHelper(awsMock, context);
assert.deepEqual(awsHelper._config, {});
done();
});
});
it('should return null if evn does not exist in invokedFunctionArn', (done) => {
const badContext = {
invokedFunctionArn: 'arn_123abs_prod:'
describe('AwsHelper.Lambda.invoke', function () {
it('should throw an error if the params.FunctionName is not set', function (done) {
try {
AwsHelper.Lambda.invoke();
} catch (e) {
// console.log(e);
var expected_err_msg = 'Error: params.FunctionName is required';
assert(e.toString().indexOf(expected_err_msg) > -1);
done();
}
});
it('should (Mock) invoke the function (using aws-sdk-mock)', function (done) {
var context = {
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda'
};
var awsMock = require('aws-sdk-mock');
// set up the mock for lambda invocation using aws-sdk-mock:
awsMock.mock('Lambda', 'invoke', 'totes worked');
// instantiate the helper module:
AwsHelper(awsMock, context, {});
// assert.equal(awsHelper.env, '$LATEST'); // confirm correctly instantiated
let env = helper.getEnvironment(badContext);
assert.equal(env, null);
done();
var params = {
FunctionName: 'MyAmazingLambda',
Payload: { 'hello': 'world' },
Qualifier: ''
};
AwsHelper.Lambda.invoke(params, function (err, data) {
assert(err === null);
assert(data === 'totes worked');
done();
});
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc