Search code examples
pythonazureazure-devopsazure-functionsazure-function-app

How can you deploy an Azure Function from within a Python script


In the same way that you would deploy a storage account or a upload a blob file from Python.

I am essentially looking for the Python equivalent of the following bash commands

  1. az functionapp create --resource-group $RESOURCE_GROUP_NAME --os-type Linux --consumption-plan-location $AZ_LOCATION --runtime python --runtime-version 3.6 --functions-version 2 --name $APP_NAME --storage-account $STORAGE_ACCOUNT_NAME

  2. func new --name $FUNC_NAME --template "Azure Queue Storage trigger"

  3. func azure functionapp publish $APP_NAME --build-native-deps

A cop-out would be to just have the Python script run the shell commands, but I am looking for a more elegant solution if one exists.


Solution

  • I am essentially looking for the Python equivalent of the following bash commands

    If you check the python sdk of azure or check the REST API document of azure, you will find there is no Ready-made method.Basically, there are two situations to discuss:

    If you want to deploy azure function to windows OS, then just use any python code to upload local function structure to related storage file share(The premise is that the function app has been created on azure.).

    But if you want to deploy azure function to linux OS, then it will not be as simple as deploying to windows OS. It needs to perform additional packaging operations, and the specific logic may need to check the underlying implementation of azure cli.

    A cop-out would be to just have the Python script run the shell commands, but I am looking for a more elegant solution if one exists.

    For Linux-based azure function, I think you don’t have to consider so much. It has many additional operations when deploy function app, so use command or run command by python to achieve this is more recommended(There is no ready-made python code or REST API that can do what you want.).