terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
909 stars 682 forks source link

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

Closed aitor94 closed 1 year ago

aitor94 commented 1 year ago

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.

shaposhnikoff commented 1 year ago

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

https://github.com/terraform-aws-modules/terraform-aws-lambda/issues/215#issuecomment-947535848

github-actions[bot] commented 1 year ago

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

antonbabenko commented 1 year ago

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.

github-actions[bot] commented 1 year ago

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.