# lambda-emulator

> Fully emulate AWS Lambda + DynamoDB application and run tests

Latest version **1.0.1** (published 2018-01-28) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-01-28 |
| First published | 2018-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 6.10.3 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Hoishin |
| Maintainers | hoishin |
| Keywords | aws, lambda, dynamo, dynamodb, docker, test, testing, emulate, simulate, serverless |

## Links

- npm: https://www.npmjs.com/package/lambda-emulator
- Repository: https://github.com/hoishin/lambda-emulator
- Homepage: https://github.com/hoishin/lambda-emulator#readme
- Issues: https://github.com/hoishin/lambda-emulator/issues
- npm.io page: https://npm.io/package/lambda-emulator

## Dependencies (1)

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

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-01-28
- 1.0.0 — 2018-01-28

## README

# lambda-emulator [![Build Status](https://travis-ci.org/Hoishin/lambda-emulator.svg?branch=master)](https://travis-ci.org/Hoishin/lambda-emulator) [![codecov](https://codecov.io/gh/Hoishin/lambda-emulator/badge.svg?branch=master)](https://codecov.io/gh/Hoishin/lambda-emulator?branch=master)

> Emulate AWS Lambda + DynamoDB application and run tests

## Prerequisites

- [nvm](https://github.com/creationix/nvm#install-script) or Node 6.10.3 installed
- Docker

## Install

```sh
npm install --save lambda-emulator
```

## Setting up

Make sure you are using Node v6.10.3

```sh
node --version
# If not 6.10.3
nvm install 6.10.3
```

Install Serverless Framework and its plugins

```sh
npm install --global serverless
npm install --save-dev serverless-dynamodb-local serverless-offline serverless-plugin-simulate
```

Download the Docker image that will be used to emulate Lambda

```sh
docker pull lambci/lambda:nodejs6.10
```

Install DynamoDB

```sh
sls dynamodb install
```

## Start emulator

You need to have 3 processes simultaneously. Open 3 terminals and run the commands below in order.

```sh
sls simulate lambda -p 4000
```

```sh
sls simulate apigateway -p 5000 --lambda-port 4000
```

```sh
sls dynamodb start -p 8000 --seed=development
```

## Usage

### SDK

```js
// Instead of require('aws-sdk') import 'lambda-emulator'
// Even though the name is emulator, this import is production-ready
// since it will just import aws-sdk if it is production
const { Lambda, DynamoDB } = require('lambda-emulator');

const lambda = new Lambda();
lambda.invoke(someParams);

const dynamodb = new DynamoDB.DocumentClient();
dynamodb.get(someParams);
```

### CLI

Use Serverless commands

```
$ sls invoke local
Plugin: Invoke
invoke local .................. Invoke function locally
    --function / -f (required) ......... Name of the function
    --path / -p ........................ Path to JSON or YAML file holding input data
    --data / -d ........................ input data
    --raw .............................. Flag to pass input data as a raw string
    --context / -c ..................... Context of the service
    --contextPath / -x ................. Path to JSON or YAML file holding context data
```

### DynamoDB Shell

[http://localhost:8000/shell](http://localhost:8000/shell)

### API Gateway Entrypoint

[http://localhost:5000](http://localhost:5000)

## API

### Lambda

- Returns `AWS.Lambda`
- Endpoint and other configs are set according to environment

### DynamoDB

- Returns `AWS.DynamoDB`
- Endpoint and other configs are set according to environment

## TODO

- Add CLI that installs Serverless framework and plugins for easier setup
- More test coverage

## License

MIT © [Hoishin (Keiichiro Amemiya)](https://github.com/Hoishin)

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