Skip to content

nelsonic/aws-lambda-helper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-lambda-helper

Collection of helper methods for lambda

Installation

$ npm install aws-lambda-helper --save

Usage

const helper = require('aws-lambda-helper');

getEnvironment

Function to get environment from context object

Example:

  const context = {
    invokedFunctionArn: 'arn:123:abs:prod'
  };

  var env = helper.getEnvironment(context); // 'prod';

In case of incorrect context or misconfigured function ARN it will return null.

validateWithSchema

Function to validate input data with defined schema

  import payloadSchema from '../schemas/validationSchema';

  const data = {
    a: 1,
    b: 'Hello World'
  };

  var result = helper.validateWithSchema(data, payloadSchema); // true

In case of validation error it will throw an error, so for safest coding practices use try/catch statements.

  try {
    helper.validateWithSchema(data, payloadSchema);
  } catch (error) {
    // handle an error
  }

About

Collection of helper methods for lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%