Encountered an error (ServiceUnavailable) from host runtime on Azure Function App

127 views Asked by At

I'm deploying a zip package as an Azure function with the use of Terraform. The relevant code fragments below:

resource "azurerm_storage_account" "mtr_storage" {
  name                     = "mtrstorage${random_string.random_storage_account_suffix.result}"
  resource_group_name      = azurerm_resource_group.mtr_rg.name
  location                 = azurerm_resource_group.mtr_rg.location
  account_kind             = "BlobStorage"
  account_tier             = "Standard"
  account_replication_type = "LRS"

  network_rules {
    default_action             = "Deny"
    ip_rules                   = ["127.0.0.1", "my.id.addr.here"]
    virtual_network_subnet_ids = [azurerm_subnet.mtr_subnet.id]
    bypass                     = ["AzureServices", "Metrics"]
  }

  tags = {
    environment = "local"
  }
}

resource "azurerm_storage_blob" "mtr_hello_function_blob" {
  name                   = "MTR.ListBlobsFunction.publish.zip"
  storage_account_name   = azurerm_storage_account.mtr_storage.name
  storage_container_name = azurerm_storage_container.mtr_hello_function_container.name
  type                   = "Block"
  source                 = "./example_code/MTR.ListBlobsFunction/MTR.ListBlobsFunction.publish.zip"
}

resource "azurerm_service_plan" "mtr_hello_function_svc_plan" {
  name                = "mtr-hello-function-svc-plan"
  location            = azurerm_resource_group.mtr_rg.location
  resource_group_name = azurerm_resource_group.mtr_rg.name
  os_type             = "Linux"
  sku_name            = "B1"

  tags = {
    environment = "local"
  }
}

data "azurerm_storage_account_blob_container_sas" "storage_account_blob_container_sas_for_hello" {
  connection_string = azurerm_storage_account.mtr_storage.primary_connection_string
  container_name    = azurerm_storage_container.mtr_hello_function_container.name

  start  = timeadd(timestamp(), "-5m")
  expiry = timeadd(timestamp(), "5m")

  permissions {
    read   = true
    add    = false
    create = false
    write  = false
    delete = false
    list   = false
  }
}

resource "azurerm_linux_function_app" "mtr_hello_function" {
  name                       = "mtr-hello-function"
  location                   = azurerm_resource_group.mtr_rg.location
  resource_group_name        = azurerm_resource_group.mtr_rg.name
  service_plan_id            = azurerm_service_plan.mtr_hello_function_svc_plan.id
  storage_account_name       = azurerm_storage_account.mtr_storage.name
  storage_account_access_key = azurerm_storage_account.mtr_storage.primary_access_key

  app_settings = {
    "FUNCTIONS_WORKER_RUNTIME"    = "dotnet"
    "WEBSITE_RUN_FROM_PACKAGE"    = "https://${azurerm_storage_account.mtr_storage.name}.blob.core.windows.net/${azurerm_storage_container.mtr_hello_function_container.name}/${azurerm_storage_blob.mtr_hello_function_blob.name}${data.azurerm_storage_account_blob_container_sas.storage_account_blob_container_sas_for_hello.sas}"
    "AzureWebJobsStorage"         = azurerm_storage_account.mtr_storage.primary_connection_string
    "AzureWebJobsDisableHomepage" = "true"
  }

  site_config {
    always_on                              = true
    application_insights_connection_string = azurerm_application_insights.mtr_ai.connection_string

    application_stack {
      dotnet_version              = "8.0"
      use_dotnet_isolated_runtime = true
    }

    cors {
      allowed_origins = ["*"]
    }
  }

  tags = {
    environment = "local"
  }
}

The zip file is uploaded to the storage account, it is downloadable and has the correct structure (or so I think). Function App is created as well, however when I scroll down to see the functions, it tells me there was an error loading functions: Encountered an error (ServiceUnavailable) from host runtime. It's probably some configuration error, but I just can't see it. Also I went to the advanced tools tab and in wwwroot there's only one file named run_from_package_failure.log. Its contents are:

RunFromPackage> Failed to download package from https://mtrstorageqbr56n79h4.blob.core.windows.net/hello-function-releases/MTR.ListBlobsFunction.publish.zip?sv=2018-11-09&sr=c&st=2024-03-31T12:09:08Z&se=2024-03-31T12:19:08Z&sp=r&spr=https&sig=c6dhOCRPL%2BEQujbuq0589D2MXFN5eXfBmhow1QWSfHU%3D. Return code: 1 - (this URL is malformed, I swapped some characters ;) ). However when I go to the url the log contains, the zip file gets downloaded successfully...

0

There are 0 answers