Search code examples
amazon-web-servicesnpmaws-lambdanode-modulesaws-lambda-layers

Require dependencies in custom code aws lambda layer


is it possible to create a aws lamda layer with custom code as shared codebase for multiple lambda functions, that has his own dependencies? Im trying to create a layer, that accesses a dynamodb-table with the aws-sdk. I looked up the aws documentation and multiple websites, but I did not find a way to create a layer with own dependencies.

Some other possible solutions, I thought about, were a custom nodejs package, that I include in every lambda function, or an additional lambda function, that my functions invoke. Any opinions on these ideas ?

Thank you for your advice.


Solution

  • since AWS layers are formed from a zip, they are generally immutable in their particular version. You should just include whatever libraries are needed as part of the layer if they are not already part of the standard available libraries a lambda has access to (The sdk for a given language is automatically included in all images regarding that language across all of AWS)

    The only 'dependencies' you can add to a layer is what languages/versions it is possible to use it with - so you can require a given layer will only work with node 12 or node 14 or a combination there-in, and you can expect the given libraries that the lambda node image comes with will always be there - anything else, you should add to your layer.