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
911 stars 683 forks source link

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

Closed willkara closed 1 year ago

willkara commented 1 year ago

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.

⚠️ Note

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

Versions

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

donsokolone commented 1 year ago

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.

antonbabenko commented 1 year ago

Yes.

https://github.com/terraform-aws-modules/terraform-aws-lambda/blob/da9b781dea7d9b52cdbad9f16bb5e22e21f1b790/package.tf#L2

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.