简体   繁体   中英

AWS Lambda not updating using Terraform source_code_hash property

I have a Terraform configuration for creating a Lambda resource and am using the source_code_hash property to detect changes to the zip. I am also uploading a separate file that contains the SHA256 hash of the file along with the zip file to S3.

I am able to do the deploy once, but then the problem is that the running Lambda is not getting updated after I update the zip and in the build log I am seeing "Still creating..."

How can I see the value of the source_code_hash property? I just see + source_code_hash = (known after apply) both in the plan output and the apply output so I don't know if the value is getting updated or not.

My code is below:

data "aws_s3_object" "source_hash" {
  bucket = "dap-bucket-2"
  key    = "lambda.zip.sha256"
}

resource "aws_lambda_function" "lambda" { 
  function_name    = "lambda_function_name"
  s3_bucket        = "dap-bucket-2"
  s3_key           = "lambda.zip"
  handler = "template.handleRequest"
  runtime = "java11"
  role    = aws_iam_role.lambda_exec.arn
  source_code_hash = "${data.aws_s3_object.source_hash.body}"
  publish = true
} 

For s3 objects, ususually you would use etag :

source_code_hash = data.aws_s3_object.source_hash.etag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM