title: How to update lambda function's source code hash after its created?
body: <p>I am using Terraform to create AWS Lambda function and also to store package in the S3 bucket. For brevity I am not including all the code</p>
  <pre><code>// Create S3 Bucket
  resource &quot;aws_s3_bucket&quot; &quot;this&quot; {
       bucket = var.s3_bucket
  }
  
  
   // Create lambda function
  resource &quot;aws_lambda_function&quot; &quot;middleware&quot; {
    function_name = var.function_name
  
    s3_bucket = var.s3_bucket
    s3_key    = var.s3_bucket_key
    source_code_hash = var.source_code_hash  //to trigger updates
  
  
    runtime = &quot;nodejs14.x&quot;
    memory_size = 1024
    timeout = 900
    handler = &quot;dist/src/lambda.handler&quot;
  
    role = var.role
  
    environment {
      variables = {
        DATABASE_URL = &quot;postgres://****&quot;
      }
    }
  }
  </code></pre>
  <p>Terraform is used to create Infrastructure which does not change very often so I am planning to separate terraform deployment from the application code deployment. In this case application code is middleware code.</p>
  <p>The application code deployment (using CI/CD) will create a package and upload it to S3 bucket that lambda will be using. However every time new package is generated its <code>source_code_hash</code> will be different and I believe lambda will require updated hash.</p>
  <p><strong>Question</strong>
  1&gt; During the application deployment, I don't want to apply terraform again by passing new source_code_hash. (That could be error prone process by accidently updating infrastructure)
  How do I update lambda_function's source code hash after its created as a part if CI/CD?</p>
  <p>2&gt;Is this the correct flow I am using by separating Infrastructure deployment?</p>