Azure FunctionApps list not returning functions on Scala

Joe Devilla 20 Reputation points
2025-03-07T18:40:23.8733333+00:00

On my Azure account, I have setup 2 FunctionApps as myself. I am doing this via the Contributor role. I can view it via the CLI:

az functionapp list --resource-group <my subscription>

I am trying to do the same via a Scala app. The identity has both the Contributor and the Reader roles, so it should be able to read all resources.

      val profile = new AzureProfile(params.azureTenantId, params.azureSubscriptionId, AzureEnvironment.AZURE)
      val credential = params.getCredential()
      val azure = AzureResourceManager.authenticate(credential, profile).withSubscription(params.azureSubscriptionId)

When looking for VMs or VPCs, I get return values. However, when I try to do the same with FunctionApps, I get an empty list. I am expecting the same results as the CLI call:

      val test = azure.functionApps().list().asScala.toList
      logger.error("Test length is "+test.size)

In this case, I end up with an empty list. Both the CLI and the Scala app are using the Contributor / Reader roles, but the Scala app is not returning values.

Am I missing something?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

Accepted answer
  1. Dasari Kamali 425 Reputation points Microsoft External Staff Moderator
    2025-03-10T13:16:34.0966667+00:00

    Hi @Joe Devilla

    Thank you for reaching out to MS Q&A.

    The issue occurred because your Scala app isn’t specifying the resource group when listing the Function Apps. The CLI works because you’re providing the --resource-group parameter.

    • To resolve this, use the val functionApps = azure.functionApps().listByResourceGroup(resourceGroup).asScala.toList in your Scala code to list the Azure Function Apps.

    Also, ensure that the Reader role is assigned to the Service Principal in the Resource Group.

    
    import com.azure.identity.DefaultAzureCredentialBuilder
    
    import com.azure.resourcemanager.AzureResourceManager
    
    import com.azure.core.management.profile.AzureProfile
    
    import com.azure.core.management.AzureEnvironment
    
    import scala.jdk.CollectionConverters._
    
    object KamApp {
    
      def main(args: Array[String]): Unit = {
    
        val tenantId = "<TenantID>"
    
        val subscriptionId = "<SubscriptionID>"
    
        val profile = new AzureProfile(tenantId, subscriptionId, AzureEnvironment.AZURE)
    
        val credential = new DefaultAzureCredentialBuilder().build()
    
        val azure = AzureResourceManager
    
          .authenticate(credential, profile)
    
          .withSubscription(subscriptionId)
    
        val resourceGroup = "<resourceGroupName>"
    
        try {
    
          val functionApps = azure.functionApps().listByResourceGroup(resourceGroup).asScala.toList
    
          if (functionApps.isEmpty) {
    
            println(s"No FunctionApps found in resource group: $resourceGroup")
    
          } else {
    
            println(s"Function Apps in $resourceGroup:")
    
            functionApps.foreach(app => println(s"- ${app.name()} (${app.regionName()})"))
    
          }
    
        } catch {
    
          case e: Exception => e.printStackTrace()
    
        }
    
      }
    
    }
    
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.