Terraform 未将 Lambda 代码 zip 文件上传到 AWS [英] Terraform not uploading Lambda code zip file to AWS
问题描述
现在我的 main.tf
中有以下内容:
Right now I have the following in my main.tf
:
resource "aws_lambda_function" "terraform_lambda" {
filename = "tf_lambda.zip"
function_name = "tf_lambda"
role = "lambda_basic_execution"
handler = "tf_lambda.lambda_handler"
source_code_hash = "${base64sha256(file("tf_lambda.zip"))}"
runtime = "python3.6"
}
我的目录结构是这样的:
My directory structure is like so:
.
|-- main.tf
|-- tf_lambda.zip
|-- tf_lambda
└── tf_lambda.py
当我运行 terraform apply
然后,在控制台中,转到创建的 lambda 代码部分是空的,它会邀请我上传一个 zip 文件.如何确保代码确实被上传?
When I run terraform apply
and then, in the console, go to the lambda created the code section is empty and it invites me to upload a zip file. How do I make sure the code actually gets uploaded?
推荐答案
您也可以尝试使用 archive_file,https://www.terraform.io/docs/providers/archive/d/archive_file.html这样当您运行terraform apply"时,文件将被重新压缩并上传.
You may also try this using archive_file, https://www.terraform.io/docs/providers/archive/d/archive_file.html So that when you run "terraform apply" the file will be re-zipped and uploaded.
data "archive_file" "zipit" {
type = "zip"
source_file = "tf_lambda/tf_lambda.py"
output_path = "tf_lambda.zip"
}
resource "aws_lambda_function" "terraform_lambda" {
function_name = "tf_lambda"
role = "lambda_basic_execution"
handler = "tf_lambda.lambda_handler"
filename = "tf_lambda.zip"
source_code_hash = "${data.archive_file.zipit.output_base64sha256}"
runtime = "python3.6"
}
这篇关于Terraform 未将 Lambda 代码 zip 文件上传到 AWS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!