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
892 stars 662 forks source link

new runtime check fails for docker build #361

Closed stevie- closed 1 year ago

stevie- commented 1 year ago

Description

With the latest version 4.1.2 and 4.1.3 a new shell check for runtime parameter was introduced. This breaks our workflows on github runner ubuntu-20.04 (or any runner which has not the selected runtime version installed). We still set python3.7 runtime which is not available on the runner, which is known and thus we use docker to build our lambdas.

It seems that this check is executed before the build process switches to the docker runtime. Please check why this code is not working with the docker build setting.

Versions

Reproduction Code [Required]

{
  create      = true
  create_role = true

  function_name = "python3.7-docker-build-fails"
  handler       = "app.lambda_handler"
  runtime       = "python3.7"
  source_path = [
    {
      path             = "../lambdas/trigger-lambda/src",
      pip_requirements = "../lambdas/trigger-lambda/requirements.txt",
    }
  ]

  build_in_docker   = true
  docker_image      = "lambci/lambda:build-python3.7"
  docker_build_root = "../lambdas/trigger-lambda/docker"
}
# requirements.txt
jsonpath-ng==1.5.2

Steps to reproduce the behavior:

< Are you using workspaces? > no workspaces < Have you cleared the local cache (see Notice section above)? > clean cache < List steps in order that led up to the issue you encountered > update module to 4.1.3 and rerun unchanged code

Expected behavior

The check for runtime binary should be done inside docker container.

Actual behavior

β”‚ 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: /path/to/bin/python3
β”‚ Error Message: Traceback (most recent call last):
β”‚   File "REDACTED/aws/lambda_function/.terraform/modules/lambda/package.py", line 1403, in <module>
β”‚     main()
β”‚   File "REDACTED/aws/lambda_function/.terraform/modules/lambda/package.py", line 1399, in main
β”‚     exit(args.command(args))
β”‚   File "REDACTED/aws/lambda_function/.terraform/modules/lambda/package.py", line 1198, in prepare_command
β”‚     build_plan = bpm.plan(source_path, query)
β”‚   File "REDACTED/aws/lambda_function/.terraform/modules/lambda/package.py", line 768, in plan
β”‚     pip_requirements_step(pip_requirements, prefix,
β”‚   File "REDACTED/aws/lambda_function/.terraform/modules/lambda/package.py", line 661, in pip_requirements_step
β”‚     raise RuntimeError(
β”‚ RuntimeError: Python interpreter version equal to defined lambda runtime
β”‚ (python3.7) should be available in system PATH
β”‚
β”‚ State: exit status

Terminal Output Screenshot(s)

Additional context

AllanBenson001 commented 1 year ago

I had the same issue when merging the latest version of code into my branch for this PR - #360

A fix is included in that PR (because I was unable to proceed without it) but it might be necessary to apply the same fix to a separate branch if I can't get the other changes included in that PR merged

lorengordon commented 1 year ago

Related question: What is the appetite for running docker during the plan phase? Obviously you would need docker, and it would need to pull the image...

antonbabenko commented 1 year ago

This issue has been resolved in version 4.1.4 :tada:

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.