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

fix: Generates error in plan phase if runtime is not available #358

Closed lorengordon closed 1 year ago

lorengordon commented 1 year ago

Fixes #357

Description

Raises plan-time error if the python or nodejs runtime is not present in the PATH. This matches the apply-time behavior, but generates the error during the plan instead of waiting until the apply.

Motivation and Context

See #357

Breaking Changes

I don't think so, unless people were somehow exploiting the prior behavior. But I can't really think of a situation where anyone would want a plan-time success and an apply-time failure...

How Has This Been Tested?

lorengordon commented 1 year ago

I have validated in my own project that this does cause the necessary failure during the plan phase...

    pip_requirements_step(File(".terraform/modules/lambda/package.py", line 660, in pip_requirements_step
    raise RuntimeError(
RuntimeError: Python interpreter version equal to defined lambda runtime
(python3.8) should be available in system PATH

And also, that it still does not fail if the runtime is available. 😁

guyzyl commented 1 year ago

Now that this PR is merged, I'm getting the following error:

Program: /opt/hostedtoolcache/Python/3.9.15/x64/bin/python3
Error Message: Traceback (most recent call last):
  File "/home/runner/work/bernese/bernese/infrastructure/environments/staging/.terraform/modules/redefine_serverless.list_queries_lambda/package.py", line 1401, in <module>
    main()
  File "/home/runner/work/bernese/bernese/infrastructure/environments/staging/.terraform/modules/redefine_serverless.list_queries_lambda/package.py", line 1397, in main
    exit(args.command(args))
  File "/home/runner/work/bernese/bernese/infrastructure/environments/staging/.terraform/modules/redefine_serverless.list_queries_lambda/package.py", line 1204, in prepare_command
    content_hash = bpm.hash(hash_extra_paths)
  File "/home/runner/work/bernese/bernese/infrastructure/environments/staging/.terraform/modules/redefine_serverless.list_queries_lambda/package.py", line 636, in hash
    content_hash = generate_content_hash(content_hash_paths,
  File "/home/runner/work/bernese/bernese/infrastructure/environments/staging/.terraform/modules/redefine_serverless.list_queries_lambda/package.py", line 248, in generate_content_hash
    update_hash(hash_obj, source_dir, source_file)
  File "/home/runner/work/bernese/bernese/infrastructure/environments/staging/.terraform/modules/redefine_serverless.list_queries_lambda/package.py", line 263, in update_hash
    with open(relative_path, 'rb') as open_file:
NotADirectoryError: [Errno 20] Not a directory:
'lambda_folder/main.py/requirements.txt'

Even though I didn't set the pip_requirements = true option, and my path looks as follows:

source_path = "lambda_folder/list_queries/main.py"

An hour ago this exact same module worked as expected, but now fails.

antonbabenko commented 1 year ago

@lorengordon Could you please take a look at this issue?

lorengordon commented 1 year ago

Oh, I see the logic error. My apologies. One sec.

lorengordon commented 1 year ago

Please see https://github.com/terraform-aws-modules/terraform-aws-lambda/pull/359

github-actions[bot] commented 1 year ago

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.