-
-
Notifications
You must be signed in to change notification settings - Fork 726
Open
Description
Description
During nodejs Lambda function deployment using the Terraform AWS Lambda module, the packaging step fails because devDependencies are never installed. The npm_requirements: true setting appears to trigger an install of production dependencies only, omitting build tools like typescript and tsup. As a result, build commands (e.g. npm run build:tsup) cannot find required modules, aborting the archive creation with errors such as βCannot find module βtypescriptββ and exit code 1. Item-Locker is shown as an example, but any Node.js Lambda relying on devDependencies for compilation or bundling is affected.
Versions
-
Module version [Required]: 7.21.1
-
Terraform version:
Terraform v1.12.1
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v6.6.0
+ provider registry.terraform.io/hashicorp/external v2.3.5
+ provider registry.terraform.io/hashicorp/local v2.5.3
+ provider registry.terraform.io/hashicorp/null v3.2.4
- Provider version(s):
Providers required by configuration:
.
βββ provider[registry.terraform.io/hashicorp/aws] 6.6.0
βββ module.websocket-gateway
βΒ Β βββ provider[registry.terraform.io/hashicorp/aws] >= 5.96.0
βΒ Β βββ module.acm
βΒ Β βββ provider[registry.terraform.io/hashicorp/aws] >= 4.40.0
βββ module.item-locker
βΒ Β βββ provider[registry.terraform.io/hashicorp/null] >= 2.0.0
βΒ Β βββ provider[registry.terraform.io/hashicorp/aws] >= 5.79.0
βΒ Β βββ provider[registry.terraform.io/hashicorp/external] >= 1.0.0
βΒ Β βββ provider[registry.terraform.io/hashicorp/local] >= 1.0.0
βββ module.item-locks
βββ provider[registry.terraform.io/hashicorp/aws] >= 5.98.0
Reproduction Code [Required]
module "item-locker" {
allowed_triggers = {
apigateway = {
service = "apigateway"
source_arn = "${module.websocket-gateway.api_execution_arn}/*/*"
}
}
attach_policy_statements = true
environment_variables = {
TABLE_NAME = "item-locks"
}
function_name = "item-locker"
handler = "handler.onEvent"
memory_size = 128
policy_statements = [
{
actions = [
"dynamodb:scan",
"dynamodb:GetItem",
"dynamodb:Query",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
]
resources = [
"${module.item-locks.dynamodb_table_arn}",
"${module.item-locks.dynamodb_table_arn}/*",
]
effect = "Allow"
},
{
actions = [
"execute-api:ManageConnections",
]
resources = [
"arn:aws:execute-api:${data.aws_region.region.name}:${data.aws_caller_identity.caller.account_id}:*/staging/POST/@connections/*",
]
effect = "Allow"
},
{
actions = [
"execute-api:Invoke",
]
effect = "Allow"
resources = [
"arn:aws:execute-api:${data.aws_region.region.name}:${data.aws_caller_identity.caller.account_id}:*/staging/POST/*",
]
},
]
publish = true
recreate_missing_package = true
runtime = "nodejs22.x"
s3_bucket = "${data.aws_caller_identity.caller.account_id}-lambda-builds"
source_path = [
{
path = "item-locker"
npm_requirements = true
commands = [
"npm run build:tsup",
":zip dist",
]
},
]
store_on_s3 = true
timeout = 130
trigger_on_package_timestamp = true
source = "terraform-aws-modules/lambda/aws"
version = "~> 7.0"
}
Steps to reproduce the behavior:
- clear node_modules
- terraform apply
Expected behavior
- execute npm i
- node_modules also contains dev dependencies
Actual behavior
- node_modules only contains production dependencies
Terminal Output Screenshot(s)
β·
β Error: local-exec provisioner error
β
β with module.item-locker.null_resource.archive[0],
β on .terraform/modules/item-locker/package.tf line 67, in resource "null_resource" "archive":
β 67: provisioner "local-exec" {
β
β Error running command 'builds/1216d7d1ac3bb01244794afa4d94740f28b82a4f060d6322571c711d56f09943.plan.json': exit status 1. Output: zip: creating 'builds/1216d7d1ac3bb01244794afa4d94740f28b82a4f060d6322571c711d56f09943.zip'
β archive
β zip: Error during zip archive creation
β Traceback (most recent call last):
β File "/Users/dominik.jakielski/WebstormProjects/urlaubsguru/uniqversum/backend-galaxy/socket-service/aws-style/cdktf.out/stacks/websocket/.terraform/modules/item-locker/package.py", line 1721, in build_command
β bpm.execute(build_plan, zs, query)
β ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
β File "/Users/dominik.jakielski/WebstormProjects/urlaubsguru/uniqversum/backend-galaxy/socket-service/aws-style/cdktf.out/stacks/websocket/.terraform/modules/item-locker/package.py", line 1015, in execute
β raise RuntimeError(
β ...<5 lines>...
β )
β RuntimeError: Script did not run successfully, exit code 1: > [email protected] build:tsup
β > npx tsup --config tsup.config.ts - Error: Cannot find module 'typescript'
β Require stack:
β - /Users/dominik.jakielski/.npm/_npx/7d72304e626f8399/node_modules/tsup/dist/index.js
β - /Users/dominik.jakielski/.npm/_npx/7d72304e626f8399/node_modules/tsup/dist/chunk-2YH5KWEM.js
β - /Users/dominik.jakielski/.npm/_npx/7d72304e626f8399/node_modules/tsup/dist/cli-default.js
β at Function._resolveFilename (node:internal/modules/cjs/loader:1244:15)
β at Function._load (node:internal/modules/cjs/loader:1070:27)
β at TracingChannel.traceSync (node:diagnostics_channel:322:14)
β at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
β at Module.require (node:internal/modules/cjs/loader:1335:12)
β at require (node:internal/modules/helpers:136:16)
β at Object.<anonymous> (/Users/dominik.jakielski/.npm/_npx/7d72304e626f8399/node_modules/tsup/dist/index.js:1027:19)
β at Module._compile (node:internal/modules/cjs/loader:1562:14)
β at Object..js (node:internal/modules/cjs/loader:1699:10)
β at Module.load (node:internal/modules/cjs/loader:1313:32)
Additional context
- In my setup, i use cdktf, but converted to hcl for simplicity
Metadata
Metadata
Assignees
Labels
No labels