Demonstrates how to use an AWS Lambda with Node.js using ES modules and dependencies from a layer
Note: symlinking the node_modules folder is a simpler solution.
make
.dist/lambda-nodejs14.zip
.dist/layer.zip
.The NODE_PATH
variable is not supported by the ESM loader in Node, as seen here. In addition, the NODE_PATH
is not part of resolving import specifiers, which means the layer cannot be reached.
The workaround would be to use a module from a layer, which would be to expose the dynamic import function from the module that you require.
Using that workaround I cannot
import { s3 } from 'esm_in_layer'
but use explicit, async loading. Adding this boilerplate code to all lambdas adds additional workload which I want to avoid.