Lambda Param
Parse parameters in AWS Lambda.
Installation
$ npm install @repit/lambda-param --save
Usage
'use strict'
const param = require('@repit/lambda-param')
exports.handler = (event, context, callback) => {
// Parse `foo` from `queryStringParameters`.
param(event, 'foo') // value || null
// Parse `foo` from `pathParameters`.
param.path(event, 'foo') // value || null
// Parse `foo` from `headers`.
param.headers(event, 'foo') // value || null
// Parse `foo` from `queryStringParameters`,
// and test it against a given regexp.
param(event, 'foo', /^[A-Z]{2}$/) // value || null
// Parse `foo` from `queryStringParameters`,
// and make sure it is contained in a given object.
param(event, 'foo', null, { foo: true }) // value || null
// Parse `foo` from `queryStringParameters`,
// and make sure it is contained in a given array.
param(event, 'foo', null, ['foo']) // value || null
}
License
MIT