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
885 stars 658 forks source link

pip install --no-deps in commands does not work #557

Closed stamak closed 2 months ago

stamak commented 2 months ago

Description

Trying to put numpy into separate layer with --no-deps in commands but it does not work

https://repost.aws/knowledge-center/lambda-import-module-error-python

Versions

Reproduction Code [Required]

module "lambda_layer_numpy" {
  source = "terraform-aws-modules/lambda/aws"

  create_function = false
  create_layer    = true

  layer_name               = "lambda-layer-numpy"
  compatible_runtimes      = ["python3.10"]
  compatible_architectures = ["arm64"]

  source_path = [
    {
      path = "${path.module}/layer"
      commands = [
        "cd `mktemp -d`",
        "pip3 install --target=. --no-deps numpy",
        ":zip . python/"
      ]
    }
  ]
}

Steps to reproduce the behavior:

Expected behavior

Executed commands

Actual behavior

Uploaded file must be a non-empty zip

Terminal Output Screenshot(s)

module.lambda_layer_numpy.null_resource.archive[0]: Creating...
module.lambda_layer_numpy.null_resource.archive[0]: Provisioning with 'local-exec'...
module.lambda_layer_numpy.null_resource.archive[0] (local-exec): Executing: ["python3" ".terraform/modules/lambda_layer_numpy/package.py" "build" "--timestamp" "1712169865535970000" "builds/5f862cceeb76a95db37612cfb4237795039a66e098c11a6a40ff504
9e69ba092.plan.json"]
module.lambda_layer_numpy.null_resource.archive[0] (local-exec): zip: creating 'builds/5f862cceeb76a95db37612cfb4237795
039a66e098c11a6a40ff5049e69ba092.zip' archive
module.lambda_layer_numpy.null_resource.archive[0] (local-exec): exit_code: 0
module.lambda_layer_numpy.null_resource.archive[0] (local-exec): zip: adding content of directory: .terraform/modules/lambda_layer_numpy.null_resource.archive[0] (local-exec): Created: builds/5f862cceeb76a95db37612cfb4237795039a66e098c11a6a40ff5049e69ba092.zip
module.lambda_layer_numpy.null_resource.archive[0]: Creation complete after 2s [id=4644124653626418376]
...
β”‚ Error: creating lambda layer: InvalidParameterValueException: Uploaded file must be a non-empty zip
β”‚ {
β”‚   RespMetadata: {
β”‚     StatusCode: 400,
β”‚     RequestID: "03fa6a11-2e52-4300-a7db-c07eedee01e8"
β”‚   },
β”‚   Message_: "Uploaded file must be a non-empty zip",
β”‚   Type: "User"
β”‚ }
pdecat commented 2 months ago

The main issue here seems that the working dir of the shell in which commands are executed is changed by "cd `mktemp -d`", which was a supported use case before #534.

antonbabenko commented 2 months ago

This issue has been resolved in version 7.2.6 :tada:

github-actions[bot] commented 1 month 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.