terraform-aws-modules/terraform-aws-lambda

Error creating lamda layer: Could not locate source_path "null".

aitor94 opened this issue · 4 comments

Error creating lambda layer

I'm triying to create a lambda layer using lambda_layer_pip_requirements, creating the layer using the requirements.txt file. The .tf file have this contents:

module "lambda_layer_pip_requirements" {
  source = "terraform-aws-modules/lambda/aws"

  create_layer    = true
  create_function = false

  layer_name          = "testdev"
  compatible_runtimes = ["python3.9"]
  runtime             = "python3.9"

  source_path = "${path.module}/../../../aws/lambda"
}

Module version is 4.12.1. I have checked the path "${path.module}/../../../aws/lambda" and exists. Inside this path exists the requirements file. I have also tried using the absolut path and still getting the same error when running terraform apply.

The complete error is the following:

╷
│ Error: invalid value for name (must match [\w+=,.@-])
│
│   with module.lambda.aws_iam_role.lambda[0],
│   on .terraform/modules/lambda/iam.tf line 97, in resource "aws_iam_role" "lambda":
│   97:   name                  = local.role_name
│
╵
╷
│ Error: invalid value for name (must match [\w+=,.@-])
│
│   with module.lambda.aws_iam_policy.logs[0],
│   on .terraform/modules/lambda/iam.tf line 136, in resource "aws_iam_policy" "logs":
│  136:   name   = "${local.policy_name}-logs"
│
╵
╷
│ Error: External Program Execution Failed
│
│   with module.lambda.data.external.archive_prepare[0],
│   on .terraform/modules/lambda/package.tf line 10, in data "external" "archive_prepare":
│   10:   program = [local.python, "${path.module}/package.py", "prepare"]
│
│ The data source received an unexpected error while attempting to execute the program.
│
│ Program: /home/aitor/.pyenv/shims/python3
│ Error Message: Could not locate source_path "null".  Paths are relative to directory where `terraform plan` is being
│ run ("/home/user/workspace/project/terraform/environments/dev")
│
│ State: exit status 1

I also have tried this source path:

source_path = [
    {
      path             = "${path.module}/../../../aws/lambda"
      pip_requirements = true
      prefix_in_zip    = "python"
    }
  ]

Getting the same error. The path exists and also the requrements file.

I had the same error, then I came across this discussion, maybe it will help

#215 (comment)

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

I can't reproduce this issue myself. It seems that there are some more arguments not shown in the original description of this issue.

Please try to run the code in examples/complete since it is very similar to the one you're providing.

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.