Allow users to manually build and zip packages (without using :zip)
AWS provider version: >= 4.0.0 Terraform version: 1.2.4
Problem
I am using the AWS runtime SDK for C++-based development. This means my runtime is "provided". I am compiling my commands using the aws-lambda-package-function CMAKE function. This creates a function.zip file with all the relevant libraries and binaries for the execution of lambda. This also means I cannot use the bundling described in terraform as below.
module "my_lambda_function" {
source = "terraform-aws-modules/lambda/aws"
function_name = "my_lambda_function"
handler = "function"
runtime = "provided"
architectures = ["x86_64"]
memory_size = 1024
timeout = 1000
attach_policy_json = true
policy_json = data.aws_iam_policy_document.my_lambda_function.json
source_path = [
{
path = "${path.module}/lambda/my_lambda_function",
commands = [
"sh ${local.build_cpp_path2} ./",
# the above bash script performs mkdir build; cd build; cmake ../source; make aws-lambda-package-function
":zip"
]
}
]
}
This is because this creates a zip file containing function.zip.
Feature request
Be able to directly use the function.zip, ideally rename it using the hash of the code or the zip file itself. It seems having the zip step is essential which otherwise complains with ValueError: BuildPlanManager.plan() should be called first which understandably is used for hashing I believe. Or am I wrong? The outdated alternative from https://github.com/claranet/terraform-aws-lambda had $filename which made it possible to move the function.zip file to the destination of $filename
I would like to steer away from having separately bundled packages as my workaround is concise and more readable.
Possible workaround.
module "my_lambda_function" {
source = "terraform-aws-modules/lambda/aws"
function_name = "my_lambda_function"
handler = "function"
runtime = "provided"
architectures = ["x86_64"]
memory_size = 1024
timeout = 1000
attach_policy_json = true
policy_json = data.aws_iam_policy_document.my_lambda_function.json
source_path = [
{
path = "${path.module}/lambda/my_lambda_function",
commands = [
"sh ${local.build_cpp_path2} ./",
# above bash script does the same compilation plus, "unzip function.zip -d function_binaries"
# now I have binaries and libs in function_binaries
"cd build/function_binaries", # change directory to extracted function
":zip" # compress again
]
}
]
}
Additional context
The workaround is getting the thing done, but I would like to know if there is a better solution to address this problem. Apologies if I have missed something.
Thanks
This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days
This issue was automatically closed because of stale in 10 days
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.