Create Azure function app and function inside while importing the existing Azure function python code and all dependencies along with it

Gautam, Ravikant 0 Reputation points
2023-08-23T13:41:27.6633333+00:00

I am trying to create the Azure function app along with function and I also want to import the existing function Python code and external dependencies along with it.

I have tried few approaches and I am able to create the function app and function as well with blob trigger but I am not able to import the python code in the function.

I am providing my code snippet for the same

"resources": [
      {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-05-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "Storage"
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('hostingPlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Y1",
        "tier": "Dynamic",
        "size": "Y1",
        "family": "Y"
      },
      "properties": {
        "computeMode": "Dynamic",
        "reserved": true
      }
    },
    {
      "type": "Microsoft.Insights/components",
      "apiVersion": "2020-02-02",
      "name": "[variables('applicationInsightsName')]",
      "location": "[parameters('appInsightsLocation')]",
      "tags": {
        "[format('hidden-link:{0}', resourceId('Microsoft.Web/sites', variables('applicationInsightsName')))]": "Resource"
      },
      "properties": {
        "Application_Type": "web"
      },
      "kind": "web"
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2022-03-01",
      "name": "[parameters('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp,linux",
      "properties": {
        "reserved": true,
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
          "linuxFxVersion": "[parameters('linuxFxVersion')]",
          "appSettings": [
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('Microsoft.Insights/components', parameters('functionAppName')), '2015-05-01').InstrumentationKey]"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2022-09-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2022-09-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(parameters('functionAppName'))]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "[parameters('functionWorkerRuntime')]"
            },
            {
              "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
              "value": "true"
            }
          ]
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    },
    
    {
      "type": "Microsoft.Storage/storageAccounts/blobServices",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', parameters('storageAccountName'), 'default')]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    },
    {
      "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
      "apiVersion": "2019-06-01",
      "name": "[format('{0}/{1}/{2}', parameters('storageAccountName'), 'default', format('{0}default{1}', parameters('storageAccountName'), parameters('blobContainerName')))]",
      "properties": {
        "publicAccess": "None"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/blobServices', parameters('storageAccountName'), 'default')]"
      ]
    },
    {
      "type": "Microsoft.Web/sites/functions",
      "apiVersion": "2018-02-01",
      "name": "[format('{0}/{1}', parameters('functionAppName'), format('{0}', parameters('functionName')))]",
      "properties": {
        "config": {
          "bindings": [
            {
              "name": "myBlob",
              "type": "blobTrigger",
              "direction": "in",
              "path": "[format('default/{0}/{{name}}', parameters('blobContainerName'))]",
              "connection": "AzureWebJobsStorage"
            }
          ],
          "disabled": false
        },
        "script_href": "https://blob-url/root_folder/existing_function_name/__init__.py",
        "script_root_path_href": "https://blob-url/root_folder/existing_function_name/",
        "language": "python",
        "isDisabled": false
      },

      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts/blobServices/containers', parameters('storageAccountName'), 'default', format('{0}default{1}', parameters('storageAccountName'), parameters('blobContainerName')))]"
      ]
    }
	]
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,134 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Mike Urnun 9,821 Reputation points Microsoft Employee
    2023-08-29T02:13:14.14+00:00

    Hello, @Gautam, Ravikant - Thanks for reaching out. The ARM (Azure Resource Manager) is used primarily for creating the environment (underlying infra & config resources) necessary for running your Functions code. Once those resources are created on Azure, building and publishing the Python functions code is a task that is carried out separately using tools like VS Code, and Azure CLI. For a complete list of options, please review: Azure Functions Python developer guide - Publishing to Azure

    Note that there are multiple ways to accomplish Build and Publish respectively.

    If your end goal is to automate both ARM & Python function deployments in a single deployment operation, we recommend exploring the following:

    I hope this helps. If you have any questions or need further assistance, feel free to raise them in the comments section below. Thanks!

    0 comments No comments

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.