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 2.0.0 to 2.1.0

test/lib/dynamodb.js

10

package.json
{
"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"
}
}

58

README.md

@@ -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

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