3.0.0-4 • Published 4 months ago

@byaga/lamb-stew v3.0.0-4

Weekly downloads
111
License
MIT
Repository
-
Last release
4 months ago

lamb-stew

A collection of utilities for AWS Lambda functions. These methods are generally assuimg that the event structure will follow the APIGateway proxy format as this is a reasonable structure that I have found can easily be utilized even for non API Gateway lambdas as it provides a clean mechanism for separating metadata about the event from the actual payload.

Installation

npm install @byaga/lamb-stew

Usage

Enhance

The enhance function is a higher-order function that wraps another function (lambda) and adds logging and error handling. It first sets up the logging context, then calls the wrapped function (lambda). If an error occurs while calling the lambda, it logs the error and returns a server error response. It also allows customizing the response by passing an onResponse function in the options.

import { enhance } from '@byaga/lamb-stew';

const options = {
  service: 'my-service',
  name: 'my-lambda-function',
  onResponse: (response, event) => {
    // Customize the response
    return response;
  }
};

const myLambdaFunction = async (event, context, callback) => {
  // Your lambda function logic here
};

const enhancedFunction = enhance(options)(myLambdaFunction);

In this example, myLambdaFunction is your AWS Lambda function. The enhance function wraps myLambdaFunction and adds logging and error handling. If an error occurs while calling myLambdaFunction, enhance logs the error and returns a server error response. The onResponse function in the options allows you to customize the response.

Options

The enhance function accepts an options object with the following properties:

  • service (required): The name of your service. This is used for logging.
  • name (optional): The name of your lambda function. This is used for logging. If not provided, 'lambda-handler' is used.
  • onResponse (optional): A function that allows you to customize the response. It receives the response and the event as arguments.

License

MIT

3.0.0-4

4 months ago

3.0.0-3

4 months ago

3.0.0-2

4 months ago

3.0.0-1

4 months ago

1.0.10

6 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.2

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2-0

1 year ago

1.0.0-11

1 year ago

1.0.0-9

1 year ago

1.0.0-8

1 year ago

1.0.0-5

1 year ago

1.0.0-4

1 year ago

1.0.0-7

1 year ago

1.0.0-6

1 year ago

1.0.0-1

1 year ago

1.0.0-3

1 year ago

1.0.0-2

1 year ago

1.0.0-10

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

1.0.0-0

1 year ago

0.6.3

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.7

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.1.6

3 years ago

0.3.3

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago