|
1 | 1 | # serverless-plugin-layer-manager
|
2 |
| -Plugin for the Serverless framework that offers improved AWS Lambda layer management |
| 2 | +Plugin for the Serverless framework that offers improved AWS Lambda layer management. |
| 3 | + |
| 4 | +The Serverless framework supports AWS Lambda layers, but there are some shortcomings: |
| 5 | + |
| 6 | +* When creating Node.JS layers from local directories you create a directory containing a `nodejs` folder with a `package.json` file in it. However, the Serverless framework will not automatically install the dependencies used by the layer, so it needs to be done manually using e.g. hooks. |
| 7 | + |
| 8 | +* Layers are not exported by default. To export a layer you must declare your XxxLambdaLayer resources under `Output` and add an `Export` property manually |
| 9 | + |
| 10 | +* If using `retain: true` on your layers, it's not possible to reference them from functions in the same stack, since layer names will be appended with a unique version hash. You either need to stop using `retain` or put your layers in a separate stack and export them using the trick above, and then reference them from your functions in another stack. |
| 11 | + |
| 12 | +This plugin fixes all these problems by automatically adding hooks to invoke `npm install` on each declared Node.JS layer, and by transforming the generated CloudFormation template to export the layers and to properly reference the versioned layers from functions. |
| 13 | + |
| 14 | +Installation: |
| 15 | + |
| 16 | +``` |
| 17 | +npm install --save-dev serverless-plugin-layer-manager |
| 18 | +``` |
| 19 | + |
| 20 | +serverless.yml: |
| 21 | + |
| 22 | +``` |
| 23 | +... |
| 24 | +plugins: |
| 25 | + - serverless-plugin-layer-manager |
| 26 | +``` |
| 27 | + |
| 28 | +That's it! You may now reference your layers from functions in the same file like |
| 29 | + |
| 30 | +``` |
| 31 | +layers: |
| 32 | + lib: |
| 33 | + path: lib |
| 34 | + name: dev-foo-lib |
| 35 | + description: My library |
| 36 | + retain: true |
| 37 | + |
| 38 | +functions: |
| 39 | + hello: |
| 40 | + handler: index.handler |
| 41 | + layers: |
| 42 | + - !Ref: LibLambdaLayer # TitleCase layer name followed by LambdaLayer |
| 43 | +``` |
| 44 | + |
| 45 | +The `lib` layer will be installed and its `node_modules` packaged into the artifact, and the function will use the layer. |
| 46 | + |
| 47 | +You may customize the features by adding a `layerConfig` object under `custom`, supporting the following properties: |
| 48 | + |
| 49 | +``` |
| 50 | +custom: |
| 51 | + layerConfig: |
| 52 | + installLayers: <boolean> |
| 53 | + exportLayers: <boolean> |
| 54 | + upgradeLayerReferences: <boolean> |
| 55 | + exportPrefix: <prefix used for the names of the exported layers> |
| 56 | +``` |
| 57 | + |
| 58 | +By default, all config options are true and the `exportPrefix` is set to `${AWS:StackName}-`. |
0 commit comments