# serverless-lambda-layers

> [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![Issues](https://img.shields.io/github/issues/agutoli/serverless-layers.svg)](https://github.com/agutoli/serverless-layers/issues) [![License](https://img.shields.io/

Latest version **1.4.6** (published 2019-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-lambda-layers
pnpm add serverless-lambda-layers
yarn add serverless-lambda-layers
bun add serverless-lambda-layers
```

## 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.4.6 |
| Published | 2019-12-23 |
| First published | 2019-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 70.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 229 |
| Author | Bruno Agutoli |
| Maintainers | vdtn359 |
| Keywords | Serverless, Amazon Web Services, AWS, Lambda, API Gateway, environment, layers |

## Links

- npm: https://www.npmjs.com/package/serverless-lambda-layers
- Repository: https://github.com/agutoli/serverless-layers
- Issues: https://github.com/agutoli/serverless-layers/issues
- npm.io page: https://npm.io/package/serverless-lambda-layers

## Dependencies (5)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [archiver](https://npm.io/package/archiver.md) ^3.0.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.3
- [fs-copy-file](https://npm.io/package/fs-copy-file.md) ^2.1.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.3.1

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 1.4.6 (latest) — 2019-12-23
- 1.4.5 — 2019-12-22
- 1.4.4 — 2019-12-22
- 1.4.3 — 2019-12-22

## README

# serverless-layers
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)
[![Issues](https://img.shields.io/github/issues/agutoli/serverless-layers.svg)](https://github.com/agutoli/serverless-layers/issues) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://www.npmjs.com/package/serverless-layers)
[![NPM](https://img.shields.io/npm/v/serverless-layers.svg)](https://www.npmjs.com/package/serverless-layers)
[![Build Status](https://travis-ci.org/agutoli/serverless-layers.svg?branch=master)](https://travis-ci.org/agutoli/serverless-layers)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](#contributing)

* Automatically attach layers for each lambda function
* Creates a new layer version when `package.json` was updated
* If package.json was not changed, it does not publish a new layer
* Reduces drastically lambda size
* It reduces deployment time.
* Share same layers (libraries) with all lambda functions

## Requirements

* Serverless >= 1.34.0 (layers support)
* Node >= v6.10.3
* NPM >= 3.10.10
* AWS only (sorry)
* A valid package.json file

## Install

`npm install -D serverless-layers`

or

`serverless plugin install --name serverless-layers`

Add the plugin to your `serverless.yml` file:

## Simple usage
```yaml
provider:
  ...
  deploymentBucket:
    name: 'your_bucket'

plugins:
  - serverless-layers
```

## Plugin Options
Example:

```yaml
custom:
  serverless-layers:
    packageManager: npm
```

|     Option     |    Type   |   Default   | Description |
| -------------- | --------- | ----------- | ----------- |
| packageManager |  `string` |    npm      | Possible values: npm, yarn |
| compileDir     |  `string` | .serverless | Compilation directory |
| packagePath    |  `string` | package.json | You can specify custom path for your package.json |
| compatibleRuntimes |  `array` | `['nodejs']` | Possible values: nodejs, nodejs8.10, nodejs10.x |
| layersDeploymentBucket | `string` |  | You can specify a bucket to upload lambda layers. `Required if deploymentBucket is not defined.` |
| customInstallationCommand | `string` |  | It specify a custom command to install deps ex. `MY_ENV=1 npm --proxy http://myproxy.com i -P` |

## Default Serverless Setup

This plugin will setup follow options automatically if not specified at `serverless.yml`.

|     Option     |    Type   |   Default   |
| -------------- | --------- | ----------- |
| package.individually | `bool` | false    |
| package.exclude | `array` | `['node_modules/**']` |
| package.excludeDevDependencies | `bool` | false |

## Mininal Policy permissions for CI/CD IAM users

`serverless-layers-policy.json`
```json
{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "s3:PutObject",
            "s3:GetObject"
         ],
         "Resource": "arn:aws:s3:::examplebucket"
      },
      {
         "Effect":"Allow",
         "Action":[
            "cloudformation:DescribeStacks"
         ],
         "Resource": "*"
      },
      {
         "Effect":"Allow",
         "Action":[
            "lambda:PublishLayerVersion"
         ],
         "Resource": "*"
      }
   ]
}
```


## Contributing

Yes, thank you!
This plugin is community-driven, most of its features are from different authors.
Please update the docs and tests and add your name to the package.json file.
We try to follow [Airbnb's JavaScript Style Guide](https://github.com/airbnb/javascript).

## License

MIT

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