我在尝试在 Amazon S3 上的 zip 档案中参考用户定义的元资料栏位时遇到了一些麻烦。我正在尝试使用此元资料栏位来帮助 Terraform 检测 zip 档案是否已更改,以便我可以发布新版本的 Lambda 函式。
这些是 S3 上的元资料栏位:
System defined Content-Type application/zip
User defined x-amz-meta-sha256 241461f66ba6bec6418679888f9c8b5210c1f183aabfe86d1cc2ab71cdffdcfc
这是我为 Terraform 配置所拥有的:
data "aws_s3_bucket_object" "lambda" {
bucket = "bucket"
key = "lambda/lambda.zip"
}
resource "aws_lambda_function" "lambda" {
function_name = "lambda_name"
s3_bucket = "bucket"
s3_key = "lambda/lambda.zip"
source_code_hash = "${data.aws_s3_bucket_object.lambda.metadata.x-amz-meta-sha256}"
handler = "index.handler"
runtime = "nodejs14.x"
publish = true
role = aws_iam_role.lambda_exec.arn
vpc_config {
subnet_ids = "subnet_ids"
security_group_ids = "security_group_ids"
}
}
当我尝试运行“terraform plan”时出现此错误:
Error: Missing map element
on ../../../modules/lambda/main.tf line 14, in resource "aws_lambda_function" "lambda":
14: source_code_hash = "${data.aws_s3_bucket_object.lambda.metadata.x-amz-meta-sha256}"
├────────────────
│ data.aws_s3_bucket_object.lambda.metadata is map of string with 1 element
This map does not have an element with the key "x-amz-meta-sha256".
我不确定“元资料”是否是原生 Terraform 地图资料型别。
uj5u.com热心网友回复:
它应该是:
source_code_hash = data.aws_s3_bucket_object.lambda.metadata.Sha256
0 评论