2.0.1 • Published 2 years ago

aws-lambda-response-helper v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

  1. Checkout a new branch from main
  2. Document changes in the CHANGELOG.md under a new version number (guide in the changelog)
  3. Up the version in package.json
  4. Submit a PR
2.0.1

2 years ago

1.1.9

2 years ago

2.0.0

2 years ago

1.1.8

2 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago