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.