Dotnet Lambda taking too much time to deploy in AWS

We are trying to deploy dotnet lambda function on AWS using terraform , But we have observed 2 thing

  1. Terraform takes almost 10 min to complete the deployment of a AWS lambda function . This is only happening in Dotnet code , we have tested python one and it is working perfectly fine . Can you please let us know any insights here.
  2. We are also getting this error message on console “The code editor does not support the .NET Core 3.1 (C#/PowerShell) runtime.”. I have checked AWS documentation , it seems dotnet 3.1 is supported but not sure why we are getting this behavior

Terraform Version

0.12.13

AWS provider

provider "aws" {
  version = "=3.38.0"
  region = var.region

  assume_role {
    role_arn = var.role_arn
  }
}
...

Terraform Configuration Files

resource "aws_lambda_function" "lambda" {
  filename           = local.filename
  function_name      = var.function_name
  role               = data.aws_iam_role.lambda-role.arn
  handler            = var.handler
  runtime            = var.runtime
  timeout            = var.timeout
  #dead_letter_config = var.dead_letter_config
  description        = var.description
  memory_size        = var.memory_size
  publish            = var.publish
  #dead_letter_config {
  #  target_arn = [var.dead_letter_config]
  #}
  #dead_letter_config =  var.dead_letter_config


  vpc_config         {
    subnet_ids 		= module.data-utils.aws_subnet_ids
    security_group_ids = [aws_security_group.lambda.id]
  }

  environment {
    variables = var.environment_vars
  }

  kms_key_arn        = var.kms_key_arn
  tags               = local.tags
  reserved_concurrent_executions = var.reserved_concurrent_executions

  depends_on = [null_resource.build]
}

resource "random_id" "server" {
  keepers = {
    # Generate a new id each time we switch to a new AMI id
    triggeralways = var.git_ref == "master" ? uuid() : var.git_ref
    triggeralways = uuid()
  }

  byte_length = 8
}

data "template_file" "init" {
  depends_on = [random_id.server]
  template = file("${path.module}/build/build.sh.tpl")

  vars = {
    runtime = var.runtime # pass runtime package
    curdir  = path.cwd # get current working directory

    git_repo = var.git_repo
    git_ref  = var.git_ref
    filename = local.filename
    function_name = var.function_name
    currentDirectory = ""
    project_file_path   = var.project_file_path
    #runtime=var.runtime
    unique_id = random_id.server.id
    releasePath=var.releasePath
  }
}

resource "null_resource" "build" {
  depends_on = [random_id.server]
  triggers = {
    #triggeralways = var.git_ref == "master" ? uuid() : var.git_ref
    always_run = "${timestamp()}"
  }

  provisioner "local-exec" {
    command = data.template_file.init.rendered
  }
}
...

Debug Output

module.lambda.null_resource.build (local-exec): -rw-r--r--. 1 centos centos 2.1M Aug 13 13:41 gdm-lpa-backend-sandbox-master-_d4uh8ycj5u.zip
module.lambda.null_resource.build: Creation complete after 7s [id=4714780671659555037]
module.lambda.aws_lambda_function.lambda: Modifying... [id=gdm-lpa-backend-sandbox]
module.lambda.aws_lambda_function.lambda: Modifications complete after 6s [id=gdm-lpa-backend-sandbox]

Apply complete! Resources: 2 added, 1 changed, 2 destroyed.

so this terraform takes almost 10 min to complete , we want to know the reason here. As i can see the lambda get deployed in 6sec only but it waits for 10 min to get the terraform complete.

Crash Output

Expected Behavior

Terraform should deploy the lambda function in 6 sec

Actual Behavior

Terraform takes almost 10 min to deploy the code to lambda function

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

References