aws-lambda-helper
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "aws-lambda-helper", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Collection of helper methods for lambda", | ||
@@ -19,11 +19,9 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"aws-sdk-mock": "^1.0.9", | ||
"aws-sdk": "^2.2.40", | ||
"eslint": "^1.10.3", | ||
"eslint-config-semistandard": "^5.0.0", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.4.5" | ||
}, | ||
"dependencies": { | ||
"aws-sdk": "^2.2.40" | ||
"mocha": "^2.4.5", | ||
"simple-mock": "^0.6.0" | ||
} | ||
} |
@@ -11,46 +11,38 @@ # aws-lambda-helper | ||
## Usage | ||
`var helper = require('aws-lambda-helper');` | ||
### getEnvironment | ||
Function to get environment from context object | ||
Example: | ||
```javascript | ||
var context = { | ||
invokedFunctionArn: 'arn:123:abs:prod' | ||
}; | ||
var AwsHelper = require('aws-lambda-helper'); | ||
var AWS = require('aws-sdk'); | ||
var env = helper.getEnvironment(context); // 'prod'; | ||
//Initialise the helper by passing in aws-sdk and context | ||
var awsHelper = AwsHelper(AWS, context); | ||
``` | ||
In case of incorrect context or misconfigured function ARN it will return `null`. | ||
### Invoke a Lamda function | ||
### validateWithSchema | ||
Function to validate input data with defined schema | ||
```javascript | ||
import payloadSchema from '../schemas/validationSchema'; | ||
var data = { | ||
a: 1, | ||
b: 'Hello World' | ||
}; | ||
var AwsHelper = require('aws-lambda-helper'); | ||
var AWS = require('aws-sdk'); | ||
var result = helper.validateWithSchema(data, payloadSchema); // true | ||
exports.handler = function(event, context){ | ||
// assume : context.invokedFunctionArn = invokedFunctionArn: 'arn:aws:lambda:eu-west-1:123456789:function:mylambda:prod' | ||
//Initialise the helper by passing in aws-sdk and context | ||
var awsHelper = AwsHelper(AWS, context); | ||
``` | ||
console.log(awsHelper.env); //prints: prod | ||
console.log(awsHelper.region); //prints: eu-west-1 | ||
console.log(awsHelper.region); //prints: 123456789 | ||
In case of validation error it will **throw** an error, so for safest coding practices use `try/catch` statements. | ||
```javascript | ||
try { | ||
helper.validateWithSchema(data, payloadSchema); | ||
} catch (error) { | ||
// handle an error | ||
var params = { | ||
FunctionName: 'MyAmazingLambda', | ||
Payload: { 'hello': 'world' }, | ||
Qualifier: '' | ||
}; | ||
awsHelper.Lambda.invoke(params, function (err, data) { | ||
if(err) return context.fail(err); | ||
context.succeed(data); | ||
}); | ||
} | ||
``` | ||
`` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
107492
0
22
757
0
6
47
- Removedaws-sdk@^2.2.40
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedaws-sdk@2.1692.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@4.9.2(transitive)
- Removedcall-bind@1.0.8(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedevents@1.1.1(transitive)
- Removedfor-each@0.3.5(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.1.13(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arguments@1.2.0(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-generator-function@1.1.0(transitive)
- Removedis-regex@1.2.1(transitive)
- Removedis-typed-array@1.1.15(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjmespath@0.16.0(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedpossible-typed-array-names@1.1.0(transitive)
- Removedpunycode@1.3.2(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedsafe-regex-test@1.1.0(transitive)
- Removedsax@1.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedurl@0.10.3(transitive)
- Removedutil@0.12.5(transitive)
- Removeduuid@8.0.0(transitive)
- Removedwhich-typed-array@1.1.18(transitive)
- Removedxml2js@0.6.2(transitive)
- Removedxmlbuilder@11.0.1(transitive)