Terraform not uploading a new ZIP

I ran into the same issue and what solved it for me was publishing the Lambda functions automatically using the publish argument. To do so simply set publish = true in your aws_lambda_function resource.

Note that your function will be versioned after this and each change will create a new one. Therefor you should make sure that you use the qualified_arn attribute reference if you're referring to the function in any of your other Terraform code.


There is a workaround to trigger the resource to be refreshed, if the target lambda file names are src/main.py and src/handler.py. If you have more files to be managed, add them one by one.

resource "null_resource" "lambda" {
  triggers {
    main    = "${base64sha256(file("src/main.py"))}"
    handler = "${base64sha256(file("src/handler.py"))}"
  }
}

data "archive_file" "lambda_zip" {
  type        = "zip"
  source_dir  = "src"
  output_path = "build/lambdas.zip"

  depends_on = ["null_resource.lambda"]
}

Let me know if this works for you.


There is 2 things you need to take care of:

  • upload zip file to S3 if its content has changed
  • update Lambda function if zip file content has changed

I can see you are taking care of the latter with source_code_hash. I don't see how you handle the former. It could look like that:

resource "aws_s3_bucket_object" "zip" {
  bucket               = "${aws_s3_bucket.zip.bucket}"
  key                  = "myzip.zip"
  source               = "${path.module}/myzip.zip"
  etag                 = "${md5(file("${path.module}/myzip.zip"))}"
}

etag is the most important option here.