Assistance Needed in Retrieving App Service Information Using Azure Python SDK

Huu Nguyen 40 Reputation points
2023-12-26T02:22:37.0166667+00:00

Hello support team,

I am currently in the process of verifying and ensuring that the existing App Services are utilizing the following configuration:

  • Stack: PHP
  • Major version: PHP 8
  • Minor version: PHP 8.2

User's image

To accomplish this, I need to retrieve the "General Setting" information of the App Service for inspection. I am using the Azure Python SDK, specifically the "azure-mgmt-web" package, to make API calls. I have attempted to retrieve a List of App Services by Resource Group, but it does not include the required information. Consequently, I have not yet identified a suitable API resource to obtain these details.

Could you please assist me in finding documentation or guides that would enable me to retrieve the mentioned information? I've provided an example for PHP, and additionally, I need to check App Services utilizing Python and Java.

Package link: azure-mgmt-web

Microsoft documentation link: Azure Python SDK Web Apps Operations

Thank you for your assistance.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,978 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 25,111 Reputation points Microsoft Employee Moderator
    2023-12-26T13:49:18.19+00:00

    @Huu Nguyen Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    Based on the shared information, I understand that you want to pull the runtime version of app service that is running on Linux with runtime php8.2.

    To achieve your requirement, follow the below steps and use the python code.

    • Create a service principal and assign the contributor access to it at resource group level.
    • create a .env file in your application root directory. Set the environment variable values with values obtained from the service principal creation.
    AZURE_CLIENT_ID=00000000-0000-0000-0000-000000000000
    AZURE_TENANT_ID=11111111-1111-1111-1111-111111111111
    AZURE_CLIENT_SECRET=abcdefghijklmnopqrstuvwxyz
    
    • Create an .py file and use the below code to fetch the runtime version of the app service.

    Python Code:

    from azure.mgmt.web import WebSiteManagementClient
    from azure.identity import DefaultAzureCredential
    import os
    from dotenv import load_dotenv
    
    subscription_id = "<subscriptionId>"
    
    load_dotenv(".env")
    
    token_credential = DefaultAzureCredential()
    
    Client= WebSiteManagementClient(token_credential, subscription_id)
    app=Client.web_apps.get("<ResourceGroupName>", "<WebAppName>")
    print(app.site_config.linux_fx_version)
    
    

    Note: In the above python code, we are using service principals to authenticate, here is the reference documentation for it. Also, Make the changes to above code based on your requirement.

    Feel free to reach back to me if you have any further questions on this.


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.