Closed james-mwakichako closed 1 year ago
Additional Context:
I also went ahead and used commands
option and got the following error in Windows .
module.lambdaToDynamo_lambda.local_file.archive_plan[0]: Creation complete after 0s [id=592971c7c21735af995af3dffbde97e352aae917]
module.lambdaToDynamo_lambda.null_resource.archive[0]: Creating...
module.lambdaToDynamo_lambda.null_resource.archive[0]: Provisioning with 'local-exec'...
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): Executing: ["python.exe" ".terraform/modules/lambdaToDynamo_lambda/package.py" "build" "--timestamp" "1675955070336843000" "./.terraform/test-app-ue1-lambda-builds/0b4f89a1c7e5af849c5d3a686943d420e47ef076ee13fd81af3279c678716fdf.plan.json"]
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): zip: creating './.terraform/test-app-ue1-lambda-builds/0b4f89a1c7e5af849c5d3a686943d420e47ef076ee13fd81af3279c678716fdf.zip' archive
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): zip: Error during zip archive creation
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): Traceback (most recent call last):
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): File "C:\Users\XXXXXXX\test\sampleService\infrastructure\regional\.terraform\modules\lambdaToDynamo_lambda\package.py", line 1520, in build_command
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): bpm.execute(build_plan, zs, query)
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): File "C:\Users\XXXXXXX\test\sampleService\infrastructure\regional\.terraform\modules\lambdaToDynamo_lambda\package.py", line 891, in execute
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): p = subprocess.Popen(script, shell=True, cwd=path,
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): File "C:\Users\XXXXXXX\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): self._execute_child(args, executable, preexec_fn, close_fds,
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): File "C:\Users\XXXXXXX\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1364, in _execute_child
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): assert not pass_fds, "pass_fds not supported on Windows."
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): AssertionError: pass_fds not supported on Windows.
β·
β Error: local-exec provisioner error
β
β with module.lambdaToDynamo_lambda.null_resource.archive[0],
β on .terraform\modules\lambdaToDynamo_lambda\package.tf line 67, in resource "null_resource" "archive":
β 67: provisioner "local-exec" {
β
β Error running command
β './.terraform/test-app-ue1-lambda-builds/0b4f89a1c7e5af849c5d3a686943d420e47ef076ee13fd81af3279c678716fdf.plan.json':
β exit status 1. Output: zip: creating
β './.terraform/test-app-ue1-lambda-builds/0b4f89a1c7e5af849c5d3a686943d420e47ef076ee13fd81af3279c678716fdf.zip'
β archive
β zip: Error during zip archive creation
β Traceback (most recent call last):
β File "C:\Users\XXXXXXX\test\sampleService\infrastructure\regional\.terraform\modules\lambdaToDynamo_lambda\package.py", line 1520, in build_command
β bpm.execute(build_plan, zs, query)
β File "C:\Users\XXXXXXX\test\sampleService\infrastructure\regional\.terraform\modules\lambdaToDynamo_lambda\package.py", line 891, in execute
β p = subprocess.Popen(script, shell=True, cwd=path,
β File "C:\Users\XXXXXXX\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
β self._execute_child(args, executable, preexec_fn, close_fds,
β File "C:\Users\XXXXXXX\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1364, in _execute_child
β assert not pass_fds, "pass_fds not supported on Windows."
β AssertionError: pass_fds not supported on Windows.
Terraform code
module "lambdaToDynamo_lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "4.7.1"
function_name = "${local.prefix}-lambdaToDynamo"
description = "Sample service lambda"
handler = "index.handler"
runtime = "nodejs18.x"
source_path = [
{
path = "../../lambda/src/lambdaToDynamo",
commands = [
"npm.cmd install",
":zip"
],
patterns = [
"node_modules/.+", # Include all node_modules
],
}
]
memory_size = var.memory_size
timeout = var.timeout_in_seconds
cloudwatch_logs_retention_in_days = var.cw_log_retention_in_days
environment_variables = {
"SampleTable_Name" = data.aws_dynamodb_table.demoTable.id
}
tags = local.common_tags
}
locals {
account_resource_prefix = "${var.projectPrefix}-${var.accountProfile}"
prefix = "${var.projectPrefix}-${var.app_name}-${var.environment}"
region_short = var.region == "us-east-1" ? "ue1" : "ue2"
region_prefix = "${var.projectPrefix}-${var.app_name}-${var.environment}-${local.region_short}"
account_resource_region_prefix = "${var.projectPrefix}-${var.accountProfile}-${local.region_short}"
lambda_role_arn = "arn:aws:iam::${var.allowedAccountIds[0]}:role/${local.region_prefix}-lambdaRole"
common_tags = {
environment = var.environment
}
}
I tried running this on Mac and the lambda was deployed successfully .
More updates on this. We got around this on Windows by using WSL . Thanks to @jwicks
Exactly, this is the solution all Windows users I know were using.
I am closing this issue.
@antonbabenko , could that be added in the documentation ?
@james-mwakichako Sure, please open a PR with the updated README file. Highly appreciated!
I'm going to lock this issue because it has been closed for 30 days β³. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Description
Trying to deploy a lambda on Windows and getting the following error:
module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): raise RuntimeError( module.lambdaToDynamo_lambda.null_resource.archive[0] (local-exec): RuntimeError: Nodejs interpreter version equal to defined lambda runtime (nodejs16.x) should be available in system PATH
I have verified that I have node and npm installed .I have ran into the same error on GitBash and CMD. NOT seeing this issue on Mac.
Below are the system specs: Terraform : v1.3.7 Edition Windows 10 Enterprise Version 20H2 Installed on β09/β01/β2022 OS build 19042.2486 Experience Windows Feature Experience Pack 120.2212.4190.0
Versions
Module version [Required]: 4.7.1
Terraform version: v1.3.7
Provider version(s): v4.47.0
Python version 3.10
Reproduction Code
Steps to reproduce the behavior:
Expected behavior
Module should run successfully , run
npm install
against the package.json defined in the same directory as the lambda code and deploy the lambda to AWS.Actual behavior
Full error message :
Additional context
I have found two work arounds by updating package.py :
shell=True
incheck_call
within package.py. This comes with itβs own security considerations"npm" "install"
to"npm.cmd" "install"
in the case the OS is Windows.The lambdaToDynamo dir contains two files :