I am trying to get details of function apps using python SDK and finding suitable client and methods. I can use ResourceManagementClient and get basic info on them but does not get runtime and other details. I can run CLI az functionapp list
and get all the details. I am looking to do something equivalent using python SDK
Below code will give us the list of function apps with all the details:
Enter your subscription id and resource group to their respective variables.
# Import the needed credential and management objects from the libraries.
from types import FunctionType
from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient
import os
credential = AzureCliCredential()
subscription_id = "SUBSCRIPTION_ID" #Add your subscription ID
resource_group = "RESOURCE_GROUP_ID" #Add your resource group
resource_client = ResourceManagementClient(credential, subscription_id)
resource_list = resource_client.resources.list()
print(resource_list)
column_width =36
print("Resource".ljust(column_width) + "Type".ljust(column_width)+ "Id".ljust(column_width))
print("-" * (column_width * 2))
for resource in list (resource_list) :
if (resource.type == "Microsoft.Web/sites" ) and ((resource.kind == "functionapp" ) or (resource.kind == "functionapp,linux" )) :
print(f"{resource.name:<{column_width}}{resource.type:<{column_width}}{resource.id:<{column_width}}")
Check the documentation for adding extra parameters.
Output information from my testing:
You can use the WebSiteManagementClient class to query more details of your function app.
A WebSiteManagementClient instance can instantiate the WebAppsOperations class which will allow you to perform many actions on your function app.
See sample code below that worked for me:
from azure.identity import AzureCliCredential
from azure.mgmt.web import WebSiteManagementClient
credential = AzureCliCredential()
subscription_id = "SUBSCRIPTION_ID" #Add your subscription ID
resource_group = "RESOURCE_GROUP_ID" #Add your resource group
function_app_name = "FUNCTION_APP_NAME" #Add your function app name
# Create the web management client
web_mgmt_client = WebSiteManagementClient(credential, subscription_id)
# Get function app details
function_app_details = app_service_client.web_apps.get(resource_group, function_app_name)
print(function_app_details)
# Get function app configuration details
function_app_config = app_service_client.web_apps.get_configuration(resource_group, function_app_name)
print(function_app_config)
# List function app application settings
function_app_settings = app_service_client.web_apps.list_application_settings(resource_group, function_app_name)
print(function_app_settings)
See WebAppsOperations methods for any other details you need to access.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.