简体   繁体   English

Terraform:lambda 如何在 terraform 资源 `aws_lambda_function` 中引用 s3

[英]Terraform : How lambda to refer s3 in terraform resource `aws_lambda_function`

My lambda node source code is inside the s3 bucket as a zip file I want that source to be uploaded while executing the aws_lambda_function我的 lambda 节点源代码作为 zip 文件在 s3 存储桶内 我希望在执行aws_lambda_function时上传该源代码

resource "aws_lambda_function" "terraform_lambda_func" {
  s3_bucket     = var.bucket_name
  s3_key        = "${var.zip_file_name}.zip"
  function_name = var.lambdaFunctionName
  role          = aws_iam_role.okta-iam-v1.arn
  handler       = "index.handler"
  runtime       = "nodejs16.x"
}

Wanting it doesn't cut it because that's now the way the relantionship between a lambda and its code works.想要它并不能解决问题,因为现在这就是 lambda 与其代码之间的关系的工作方式。

What the aws_lambda_function resource does is is to say: "there is a lambda function and its code is there in that S3 bucket". aws_lambda_function资源所做的是说:“有一个 lambda function,它的代码在那个 S3 存储桶中”。

Because updating the file in the bucket doesn't automatically update the code that lambda, this resource doesn't have a way to reference new file content directly.由于更新存储桶中的文件不会自动更新 lambda 的代码,因此该资源无法直接引用新文件内容。

To do so, you need an aws_s3_object resource that is able to upload a new file to lambda.为此,您需要一个能够将新文件上传到 lambda 的aws_s3_object资源。

To trigger the actual update of the lambda, you also need to pass the file hash to the aws_lambda_function .要触发 lambda 的实际更新,您还需要将文件 hash 传递给aws_lambda_function Since the aws_s3_object resource expors a source_hash property, you can link them as such.由于aws_s3_object资源导出了一个 source_hash 属性,您可以这样链接它们。

See How to update aws_lambda_function Terraform resource when ZIP package is changed on S3?请参阅当 ZIP package 在 S3 上更改时如何更新 aws_lambda_function Terraform 资源?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform:AWS Lambda 图像未更新 - Terraform: AWS Lambda with Image not updating Terraform lambda 函数验证异常 - Terraform lambda function validation exception 如何在 aws terraform 中的步骤 function 中动态引用 lambda function arn? - How to dynamically reference a lambda function arn inside step function in aws terraform? 如何使用 terraform 为 aws lambda 指定 dotnet 6 运行时? - How to specify the dotnet 6 runtime for aws lambda, using terraform? Terraform 云应用 lambda function 失败并出现 ValidationException,AWS CLI lambda 具有相同参数的创建函数成功 - Terraform Cloud apply lambda function fails with ValidationException, AWS CLI lambda create-function with same parameters succeeds 在 AWS CodeBuild 中运行 Terraform - 部署 lambda - Running Terraform in AWS CodeBuild - deploying lambda AWS Lambda function 写入 S3 - AWS Lambda function write to S3 如何从 lambda python py 文件中的 terraform 代码引用 sns arn? - how to refer sns arn from terraform code in a lambda python py file? Terraform 中的可选 CloudFront Lambda 函数关联 - Optional CloudFront Lambda function association in Terraform 通过 Terraform 添加 Lambda function 到 Kinesis Firehose - Adding a Lambda function into Kinesis Firehose via Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM