gpt4 book ai didi

amazon-web-services - Terraform 未上传新的 ZIP

转载 作者:行者123 更新时间:2023-12-04 00:14:56 24 4
gpt4 key购买 nike

我想使用 Terraform 来部署我的 lambda 函数。我做了类似的事情:

provider "aws" {
region = "ap-southeast-1"
}

data "archive_file" "lambda_zip" {
type = "zip"
source_dir = "src"
output_path = "build/lambdas.zip"
}

resource "aws_lambda_function" "test_terraform_function" {
filename = "build/lambdas.zip"
function_name = "test_terraform_function"
handler = "test.handler"
runtime = "nodejs8.10"
role = "arn:aws:iam::000000000:role/xxx-lambda-basic"
memory_size = 128
timeout = 5
source_code_hash = "${data.archive_file.lambda_zip.output_base64sha256}"
tags = {
"Cost Center" = "Consulting"
Developer = "Jiew Meng"
}
}

我发现当 test.js 没有变化时,terraform 正确检测到没有变化
No changes. Infrastructure is up-to-date.

当我更改 test.js 文件时,terraform 确实检测到更改:
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

~ aws_lambda_function.test_terraform_function
last_modified: "2018-12-20T07:47:16.888+0000" => <computed>
source_code_hash: "KpnhsytFF0yul6iESDCXiD2jl/LI9dv56SIJnwEi/hY=" => "JWIYsT8SszUjKEe1aVDY/ZWBVfrZYhhb1GrJL26rYdI="

它确实压缩了新的 zip,但是,它似乎没有使用新的 ZIP 更新功能。似乎它认为由于文件名没有变化,它没有上传......我该如何解决这个问题?

======

按照这里的一些答案,我尝试了:
  • 使用 null_resource
  • 使用带有 etag 的 S3 存储桶/对象

  • 它不会更新......为什么会这样?

    最佳答案

    我遇到了同样的问题,为我解决的是使用 publish argument 自动发布 Lambda 函数。 .为此,只需设置 publish = true在您的 aws_lambda_function资源。

    请注意,您的函数将在此之后进行版本控制,每次更改都会创建一个新的。因此,您应该确保使用 qualified_arn如果您指的是任何其他 Terraform 代码中的函数,请使用属性引用。

    关于amazon-web-services - Terraform 未上传新的 ZIP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53864550/

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