aws-lambda-response-helper
v2.0.1
Published
Response library for use with AWS Lambda, with request auditing
Downloads
25
Readme
AWS Lambda Response Helper
Overview
Simple response library for use with AWS Lambda.
Contains a collection of inbuilt response classes and an abstract Response base class that can be used to extend the library to suit implementers needs.
Only param required by a Response object is the event
, during instantiation the Response class uses this to log out information about the request for auditing purposes.
Example
import { APIGatewayProxyHandler, APIGatewayProxyEvent } from 'aws-lambda';
import { Ok, BadRequest, errorHandler } from 'aws-lambda-response-helper';
export const handler: APIGatewayProxyHandler = async (event: APIGatewayProxyEvent) => {
try {
if (!event.body) {
throw new BadRequest('Body not provided');
}
// Do some stuff with the body
// ...
// Use env vars below to customise internal behaviour around token decoding
process.env.ALR_TOKEN_HEADER_KEY = '<property in event.headers containing the auth token, default: Authorization>'
process.env.ALR_TOKEN_USER_KEY = '<property in the auth token containing the username, default: email>'
return Ok(event);
} catch (err) {
return errorHandler(err, event);
}
}
Contributing
Contributions welcome! Please follow steps below
- Checkout a new branch from main
- Document changes in the CHANGELOG.md under a new version number (guide in the changelog)
- Up the version in package.json
- Submit a PR