pythonamazon-web-servicesaws-lambdaterraformterraform-aws-modules

add 2 python files to lambda_zip in terraform


I create a lambda function using Terraform. To zip the python file, I use this:

data "archive_file" "get_incoming_lambda_zip" {
  type             = "zip"
  source_file      = "${path.module}/src/lbd_get_incoming.py"
  output_file_mode = "0666"
  output_path      = "${path.module}/bin/lbd_get_incoming.zip"
}

Previously, I was using a function defined within the lbd_get_incoming.py file. However, now I have moved the function to common/utils.py.

In order to be able to use from common.utils import lyfunction in my lambda function, I need to export the common.utils ("${path.module}/src/common/utils.py") file along with the lbd_get_incoming.py file in the zipped version.

What's the correct syntax to achieve this? If I


Solution

  • Use source_dir instead of source_file to point to a directory where both files are stored (and in proper directory structure against each other).

    If your two files come from different places, you need to put them next to each other first and then point Terraform's archive_file to them.