Layers

Lambda layers are a recent addition to the Lambda feature set and have already been built into the serverless.yml syntax. You learned about layers in a previous chapter.

To declare a layer in the Serverless Framework, we use a new top-level block called layers, as shown in the following code. We need to specify the path relative to the function's working directory. This is the directory that lambda will place the extracted files that were bundled in the layer in:

layers:
layerName:
path: /path/to/layer

This declares a layer. Now, we can attach it to a function. Notice that the reference to the layer means that our deploy command will look for that layer in our current serverless service. You'll also note that the framework capitalizes the first letter of our layer name and appends LambdaLayer. This could trip you up, so beware! 

functions:
functionName:
handler: handler.functionName
layers:
- { Ref: LayerNameLambdaLayer }

To add a layer that exists outside of the service, you can simply use the ARN identifier instead of a reference. Just like in the console, you can add up to five layers to a function.

So, that's all we need to learn about in order to understand the terminology of the Serverless Framework. In the next section, we'll put that knowledge into good use and deploy our own service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.212.124