Terraform lambda source_code_hash update with same code

前端 未结 4 621
抹茶落季
抹茶落季 2021-01-04 07:27

I have an AWS Lambda deployed successfully with Terraform:

resource \"aws_lambda_function\" \"lambda\" {
  filename                       = \"dist/subscriber         


        
4条回答
  •  攒了一身酷
    2021-01-04 07:48

    This works for me and also doesn't trigger an update on the Lambda function when the code hasn't changed

    data "archive_file" "lambda_zip" {                                                                                                                                                                                   
      type        = "zip"                                                                                                                                                                                                
      source_dir  = "../dist/go"                                                                                                                                                                                         
      output_path = "../dist/lambda_package.zip"                                                                                                                                                                         
    }                                                                                                                                                                                                                    
    
    
    resource "aws_lambda_function" "aggregator_func" {                                                                                                                                                                   
      description      = "MyFunction"                                                                                                                                                                       
      function_name    = "my-func-${local.env}"                                                                                                                                                                  
      filename         = data.archive_file.lambda_zip.output_path                                                                                                                                                        
      runtime          = "go1.x"                                                                                                                                                                                         
      handler          = "main"                                                                                                                                                                                    
      source_code_hash = data.archive_file.lambda_zip.output_base64sha256                                                                                                                                                
      role             = aws_iam_role.function_role.arn                                                                                                                                                                  
    
    
      timeout = 120                                                                                                                                                                                                      
      publish = true                                                                                                                                                                                                     
    
      tags = {                                                                                                                                                                                                           
        environment = local.env                                                                                                                                                                                                                                                                                                                                                                    
      }                                                                                                                                                                                                                  
    }                              
    

提交回复
热议问题