terraform-aws-modules/terraform-aws-lambda

Lambda build module can't find python interpreter even though it is installed

willkara opened this issue · 3 comments

Description

I am trying to use the terraform-aws-modules/lambda/aws module for a basic lambda function build. I've confirmed Python 3.9 is on my system path, but the module keeps failing.

So, as you can see, I clearly have Python 3.9.0 on the path. The module isn't finding it for some reason.

  • I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

Versions

  • Module version [Required]:

  • Terraform version:
    v1.3.1 on windows_amd64

  • Provider version(s):

    • aws >=4.9.0
    • external >=1.0.0
    • local >=1.0.0
    • null >= 2.0.0

Reproduction Code [Required]

Steps to reproduce the behavior:

module "lambda_function" {

  source = "terraform-aws-modules/lambda/aws"

  function_name = "my-lambda1"
  description   = "My awesome lambda function"
  handler       = "index.lambda_handler"
  runtime       = "python3.9"

  source_path = "./samp"

  tags = {
    Name = "my-lambda1"
  }
}

Expected behavior

Lambda function builds

Actual behavior

Program: C:\Users\e349068\AppData\Local\Programs\Python\Python39\python.exe

│ Error Message: Traceback (most recent call last):
│ File "C:\Users\e349068\source\repos\terraform-aws-lambda\examples\build-package.terraform\modules\lambda_function\package.py", line 1632, in
│ main()
│ File "C:\Users\e349068\source\repos\terraform-aws-lambda\examples\build-package.terraform\modules\lambda_function\package.py", line 1628, in main
│ exit(args.command(args))
│ File "C:\Users\e349068\source\repos\terraform-aws-lambda\examples\build-package.terraform\modules\lambda_function\package.py", line 1427, in prepare_command
│ build_plan = bpm.plan(source_path, query)
│ File "C:\Users\e349068\source\repos\terraform-aws-lambda\examples\build-package.terraform\modules\lambda_function\package.py", line 773, in plan
│ pip_requirements_step(
│ File "C:\Users\e349068\source\repos\terraform-aws-lambda\examples\build-package.terraform\modules\lambda_function\package.py", line 675, in pip_requirements_step
│ raise RuntimeError(
│ RuntimeError: Python interpreter version equal to defined lambda runtime (python3.9) should be available in system PATH

│ State: exit status 1

PS C:\Users\e349068\source\repos\terraform-aws-lambda\examples\build-package> python --version

Python 3.9.0

I ran into same problem and the root cause is that lambda module will look for python3.9.exe in your PATH when runtime = "python3.9" is set. Copying/linking to python.exe fixed this problem for me.

Yes.

python = (substr(pathexpand("~"), 0, 1) == "/") ? "python3" : "python.exe"

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.