Is it possible to call AZ Cli / Bash inside an Azure Function App?
My goal is to automatically shut down an ADX Cluster after office times as you can save costs by this.
Would be nice to call something like that where the authentification method is using an User Assigned Identity (UAI):
I would go with the python.mgmt.kusto API but it lacks connections with UAI:
Edit: It is not true that there is no interface in the KustoManagementClient. You need to use the package python-identity which has interfaces (ManagedIdentityCredential, DefaultAzureCredential) to generate credential instances from default identification methods or explicitly by passing a UAI id. The credentials can be used by KustoManagementClients.
Edit2: I would like to share my experiences and my final solution with you.
Generating a credentials instance is the best way if you want to use for the same code for local tests or in the cloud, e.g. during development of a function app. Usually the API DefaultAzureCredential should do the job but it didn't work properly. In my case, and for local tests, I explicitly had to tell it to use my CLI login:
from azure.identity import DefaultAzureCredential
credentials = DefaultAzureCredential(
exclude_environment_credential=True,
exclude_managed_identity_credential=True,
exclude_powershell_credential=True,
exclude_visual_studio_code_credential=True,
exclude_shared_token_cache_credential=True,
exclude_interactive_browser_credential=True,
exclude_cli_credential=False
)
On the cloud site I had to go with
credentials = ManagedIdentityCredential(client_id="******")
At the end my cluster finally shuts down:
mclient = KustoManagementClient(credentials, SUBSCRIPTION_ID)
cluster_operations = mclient.clusters
cluster_operations.begin_start(RG, ADX)
I must admit that I haven't checked the python CLI interface at the end but the accepted answer in this thread shows how you could do this.
Thanks!