# @philca/lambda-test-utils

> Test utils for lambdas

Latest version **1.0.12** (published 2018-07-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install @philca/lambda-test-utils
pnpm add @philca/lambda-test-utils
yarn add @philca/lambda-test-utils
bun add @philca/lambda-test-utils
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2018-07-25 |
| First published | 2018-05-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 (+10 in 2 direct dependencies) |
| Install scripts | no |
| Author | Phil Caithness |
| Maintainers | philca |

## Links

- npm: https://www.npmjs.com/package/@philca/lambda-test-utils
- npm.io page: https://npm.io/package/@philca/lambda-test-utils

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) 4.17.5
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.40.0

## Recent versions

- 1.0.12 (latest) — 2018-07-25
- 1.0.11 — 2018-06-06
- 1.0.10 — 2018-06-03
- 1.0.9 — 2018-05-12
- 1.0.8 — 2018-05-12
- 1.0.7 — 2018-05-12
- 1.0.6 — 2018-05-03
- 1.0.5 — 2018-05-03
- 1.0.4 — 2018-05-03
- 1.0.3 — 2018-05-03
- 1.0.2 — 2018-05-03
- 1.0.1 — 2018-05-03
- 1.0.0 — 2018-05-03

## README

API
===

loadDynamo(< tablename>, < data>)
------

Load a table with a record.

**Returns:** a promise.

*Where:*

**tablename:** name of dynamo table  
**data:** json object of data.  
If data is an array, each item in the array will be loaded.


deleteDynamo(< primarykey field>, < primary key value>, [sort key field], [sort key value])
------

Delete an item from a dynamo table.

**Returns:** a promise.

*Where:*

**tablename:** name of dynamo table  
**primarykey field:** field name of primary key  
**primarykey value:** value for primary key  
**sortkey field:** (optional) field name of sort key  
**sortkey value:** (optional) value for sort key


getAndDeleteItemsFromDynamo(< tablename>, < primarykey field>, < primary key value>, [sort key field])
------

Gets one or more items from a dynamo table, returns them, and deletes them.
Use this function to get the items created by the lambda under test and clean them up.

**Note:** This is an async function. Called like:

```
const addedLoki = await getAndDeleteItemsFromDynamo(process.env.DYNAMO_LOKI_TABLE, res.body.lokiId);

or

const addedMetadata = await getAndDeleteItemsFromDynamo(process.env.DYNAMO_METADATA_TABLE, 'entityKey', res.body.lokiId, 'metavalueKey');
```

**Returns:** a json object that contains an array or Items.

*Where:*

**tablename:** name of dynamo table  
**primarykey field:** field name of primary key  
**primarykey value:** value for primary key  
**sortkey field:** (optional) field name of sort key  


invokeLambda(< lambda name>, < event>, < path>)
------
Execute a lambda function.

If the environment variable *LOCAL_LAMBDA* is true, the lambda will be run locally, else the lambda within AWS (in your default account) will be run.

```
let res = await invokeLambda('golokiImages-getimagelabels', event, __dirname);
```

**Returns:** a promise.

*Where:*

**lambda_name:** The name of the lambda_name  
**event:** The json event passed to the lambda. Like:
```
const event = {
	"queryStringParameters": {},
	"pathParameters": {
		"foo": "bar"
	},
	"body": null
};
```

**path:** path to the local lambda handler. Assumes index.js in the path contains the handler.

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