gpt4 book ai didi

amazon-web-services - Terraform没有将Lambda代码zip文件上传到AWS

转载 作者:行者123 更新时间:2023-12-04 17:30:32 24 4
gpt4 key购买 nike

现在,我的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"
}

我的目录结构是这样的:
.
|-- main.tf
|-- tf_lambda.zip
|-- tf_lambda
└── tf_lambda.py

当我运行 terraform apply时,然后在控制台中转到lambda创建的代码部分为空,并邀请我上传一个zip文件。如何确定代码实际已上传?

最佳答案

您也可以使用archive_file,https://www.terraform.io/docs/providers/archive/d/archive_file.html尝试此操作
这样,当您运行“terraform apply”时,文件将被重新压缩并上传。

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"
}

关于amazon-web-services - Terraform没有将Lambda代码zip文件上传到AWS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50357651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com