Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to update lambda code on AWS console using terraform

I am creating lambda function using terraform as per the terraform syntax lambda code should be passed as a zip file. In a similar way, I am passing in a resource block and it is getting created also without any issue. But when I am trying to update lambda code using terraform in the next run it is not getting updated. Below block for reference.

data "archive_file" "stop_ec2" {
  type        = "zip"
  source_file = "src_dir/stop_ec2.py"
  output_path = "dest_dir/stop_ec2_upload.zip"
}

resource "aws_lambda_function" "stop_ec2" {
  function_name    = "stopEC2"
  handler          = "stop_ec2.handler"
  runtime          = "python3.6"
  filename         = "dest_dir/stop_ec2_upload.zip"
  role             = "..."
}

Need help to resolve this issue.

like image 623
Sunita Muneshwar Avatar asked Jun 17 '26 20:06

Sunita Muneshwar


1 Answers

Set the source_code_hash argument, so Terraform will update the lambda function when the lambda code is changed.

resource "aws_lambda_function" "stop_ec2" {
  source_code_hash = filebase64sha256("dest_dir/stop_ec2_upload.zip")
like image 152
Chin Huang Avatar answered Jun 21 '26 05:06

Chin Huang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!