resource “null_resource” “example_common_node_modules” {
triggers = {
always_trigger = timestamp()
}
provisioner "local-exec" {
working_dir = "${path.module}/../lambdas/dependency-layer"
command = "npm install && mkdir -p nodejs && ls && cp -r node_modules nodejs/"
}
}
data “archive_file” “example_common_node_modules” {
source_dir = “{path.module}/../lambdas/dependency-layer"
type = "zip"
output_path = "{path.module}/lambda-archive/dependency-layer.zip”
depends_on = [ null_resource.example_common_node_modules ]
}
resource “aws_lambda_layer_version” “example_common_node_modules” {
filename = data.archive_file.example_common_node_modules.output_path
layer_name = “${module.example_label.id}-dependency-layer”
compatible_runtimes = ["nodejs16.x"]
}
When creating new layer with following packages
{
“name”: “DependenciesLayer”,
“version”: “0.1.0”,
“main”: “index.js”,
“dependencies”: {
“uuid”: “^8.3.2”,
“axios”: “^1.4.0”
},
“scripts”: {}
}
its working fine. all node module package created.
ISSUE
while adding or removing package
eg. “chart.js”: “^4.3.3”
In Data layer not updated. it showing again the older version of node module.
chart js not added to node modules