6.7.0 • Published 4 years ago

@basemaps/lambda v6.7.0

Weekly downloads
118
License
MIT
Repository
github
Last release
4 years ago

@basemaps/lambda

Opinionated Lambda function wrappers

  • First class promise support
  • Every request is logged
  • Supports logging of timing data
  • Supports throwing of responses
import { LambdaContext, LambdaFunction, LambdaHttpResponse } from '@basemaps/lambda';

export async function handleRequest(req: LambdaContext): Promise<LambdaHttpResponse> {
    req.set('logValue', 'Something to log'); // This will be logged when the function finishes

    if (req.method == 'HEAD') return new LambdaHttpResponse(405, 'Invalid method');

    // log timing information
    req.timer.start('validate');
    await ValidateRequest(req);
    req.timer.end('validate');

    // Responses can be thrown too
    if (isInvalid) throw new LambdaHttpResponse(500, 'Something went wrong');

    const response = new LambdaHttpResponse(100, 'Continue');
    // Set Http on responses
    if (doNotCache) response.header('Cache-Control', 'max-age=0');
    return response;
}

export const handler = LambdaFunction.wrap(handleRequest, logger);
6.7.0

4 years ago

6.6.0

4 years ago

6.5.0

4 years ago

6.4.0

4 years ago

6.3.0

4 years ago

6.1.0

4 years ago

6.2.0

4 years ago

6.0.0

4 years ago

5.1.0

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.0

4 years ago

4.24.0

4 years ago

4.23.0

4 years ago

4.22.0

4 years ago

4.21.0

4 years ago

4.20.0

4 years ago

4.19.0

5 years ago

4.18.0

5 years ago

4.17.0

5 years ago

4.16.0

5 years ago

4.15.0

5 years ago

4.14.0

5 years ago

4.13.0

5 years ago

4.12.2

5 years ago

4.12.0

5 years ago

4.11.1

5 years ago

4.11.0

5 years ago

4.10.0

5 years ago

4.9.0

5 years ago

4.8.0

5 years ago

4.7.1

5 years ago

4.7.0

5 years ago

4.6.0

5 years ago

4.5.0

5 years ago

4.4.0

5 years ago

4.0.0

5 years ago

3.6.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.2.0

5 years ago