New terraform code to update old and existing Lambda function

Hello,

I’ve got a situation and I need assistance. We’ve got an existing lambda function created by the ex-employee. Now I am been asked to update that lambda function by updating its runtime and also add some layers to it.

I wrote the below Terraform code to update the existing lambda function and it is failing with the below error. Can somebody please help me to get it right.

Error Message :

Error: creating Lambda Function (xx_xxxxx_xxxpi_lambda_xxxxx_upload_processor): operation error Lambda: CreateFunction, https response error StatusCode: 409, RequestID: 5479d3fe-63b6-4778-a42e-a08999e0d41d, ResourceConflictException: Function already exist: xx_xxxxx_xxxpi_lambda_xxxxx_upload_processor

Terraform code :

module “jfrog_download_4” {

source = “terraform.xxx.xxxxxx.net/xxx/artifact/xxxx
version = “0.3.4”
common = local.common
repository = “xxx-HOSTED-xxxx-xx”
artifact = “xx_xxxxx_xxxpi_lambda_xxxxx_upload_processor.zip”
extract = false
}

resource “aws_lambda_function” “xx_xxxxx_xxxpi_lambda_xxxxx_upload_processor” {
filename = module.jfrog_download_4.file
function_name = “xx_xxxxx_xxxpi_lambda_xxxxx_upload_processor”
role = “arn:aws:iam::87xxxxxxxxxxx4:role/xx_xxxxx_xxxxx_lambda_role”
handler = “lambda_function.lambda_handler”

#source_code_hash = data.archive_file.lambda.output_base64sha256

layers = [aws_lambda_layer_version.lambda_layer.arn]

runtime = “python3.10”

}

Before you can manage an existing function, you’ll need to import it via an import block or with the terraform import CLI command. From there you should be able to terraform apply with your updated configuration details.

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function#import

1 Like

Thank you @jar-b
really appreciate your response