# lambda-utilities

> Utility functions and type definitions for AWS Lambda

Latest version **0.2.0** (published 2019-09-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install lambda-utilities
pnpm add lambda-utilities
yarn add lambda-utilities
bun add lambda-utilities
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2019-09-13 |
| First published | 2017-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | akira-miyake |

## Links

- npm: https://www.npmjs.com/package/lambda-utilities
- Repository: https://github.com/AKIRA-MIYAKE/node-lambda-utilities
- Homepage: https://github.com/AKIRA-MIYAKE/node-lambda-utilities#readme
- Issues: https://github.com/AKIRA-MIYAKE/node-lambda-utilities/issues
- npm.io page: https://npm.io/package/lambda-utilities

## Dependencies (4)

- [sinon](https://npm.io/package/sinon.md) ^7.4.2
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.528.0
- [@types/sinon](https://npm.io/package/@types/sinon.md) ^7.0.13
- [@types/aws-lambda](https://npm.io/package/@types/aws-lambda.md) ^8.10.31

## Recent versions

- 0.2.0 (latest) — 2019-09-13
- 0.1.1 — 2018-12-20
- 0.1.0 — 2018-09-04
- 0.0.3 — 2017-11-16
- 0.0.2 — 2017-08-28
- 0.0.1 — 2017-08-28

## README

# lambda-utilities
Utility functions and type definitions for AWS Lambda

## Installation

```
$ npm isntall lambda-utilities
```

## Usage

### Utilities
#### Callback
Provide mock `Callback` that implementing interface of `SinonExpectation`.
The argument `callback` is executed on `callsFake`.

```
generateMockCallback: (callback?: Callback) => MockCallback
```

#### Context
Provide mock `Context`.
`done`, `fail` and `succeed` are implementing interface of `SinonExpectation`.
If you set a function with parameters, it will be executed on `callsFake`.

```
generateMockContext: (params?: GenerateMockContext.Params) => MockContext

export namespace GenerateMockContext {
  export interface Params {
    callbackWaitsForEmptyEventLoop?: boolean
    functionName?: string
    functionVersion?: string
    invokedFunctionArn?: string
    memoryLimitInMB?: number
    awsRequestId?: string
    logGroupName?: string
    logStreamName?: string,
    identity?: CognitoIdentity,

    getRemainingTimeInMillis?: () => number

    done?: (error: any, result: any) => void,
    fail?: (arg0: any) => void,
    succeed?: (arg0: any, arg1?: any) => void
  }
}
```

#### InvokeHandler
It is a function that executes the handler of lambda.
It can be used in tests in combination with mock.

```
const handler: Handler<TestEvet, TestCallback> = (event, context, callback) => {
  setTimeout(() => {
    callback(undefined, { foo: event.foo * 2 })
  }, 1000)
}

const callback = generateMockCallback((error, result) => {
  callback.once()
  assert.equal(result.foo, 42)
  assert.ok(callback.verify())
  done()
})

invokeHandler(handler, {
  event: { foo: 21 },
  callback: callback
})
```

---
_Source: https://npm.io/package/lambda-utilities · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
