简体   繁体   中英

unable to deploy azure function app through the arm template

Hi I have created azure funnction app with .net core. I created everything through management portal. Its working fine. I am trying to write arm templates for the resource creations. So I exported arm template from portal and through azure devops I am running it to create resources. I have selected increment changes. Below is my sample template.

{
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-11-01",
            "name": "[variables('fetchSciHubProductURLName')]",
            "location": "[parameters('location')]",
            "tags": {
                "BU": "[parameters('Division')]",
                "Environment": "[parameters('environment')]"
            },
            "kind": "functionapp,linux",
            "properties": {
                "serverFarmId": "[parameters('serverfarms_APSERDEVDVLGENSEAWE01_Linux_externalid')]",
                "clientAffinityEnabled": false,
                "httpsOnly": false,
                "siteConfig": {
                  "reservedInstanceCount": "0",
                  "appSettings": [
                    {
                      "name": "AzureWebJobsStorage",
                      "value": "secrete"
                    },
                    {
                      "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                      "value": "[parameters('storageAccount01APPINSIGHTS_INSTRUMENTATIONKEY')]"
                    },
                    {
                      "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
                      "value": "[parameters('storageAccount01APPLICATIONINSIGHTS_CONNECTION_STRING')]"
                    },
                    {
                      "name": "FUNCTIONS_EXTENSION_VERSION",
                      "value": "~3"
                    },
                    {
                      "name": "FUNCTIONS_WORKER_RUNTIME",
                      "value": "dotnet"
                    },
                    {
                      "name": "WEBSITE_ENABLE_SYNC_UPDATE_SITE",
                      "value": "true"
                    },
                    {
                      "name": "WEBSITE_RUN_FROM_PACKAGE",
                      "value": "1"
                    },
                    {
                      "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
                      "value": "true"
                    },
                    {
                      "name": "test1",
                      "value": "true"
                    }
                  ]
                }
            }
        },
        {
            "type": "Microsoft.Web/sites/functions",
            "apiVersion": "2018-11-01",
            "name": "[concat(variables('fetchSciHubProductURLName'), '/getproductsfromcoordinates')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', variables('fetchSciHubProductURLName'))]"
            ],
            "properties": {
                "script_root_path_href": "https://testqwe123.azurewebsites.net/admin/vfs/home/site/wwwroot/getproductsfromcoordinates/",
                "script_href": "https://testqwe123.azurewebsites.net/admin/vfs/home/site/wwwroot/bin/DemoThirdPartyDataDownload.AzFunction.dll",
                "config_href": "https://testqwe123.azurewebsites.net/admin/vfs/home/site/wwwroot/getproductsfromcoordinates/function.json",
                "href": "https://testqwe123.azurewebsites.net/admin/functions/getproductsfromcoordinates",
                "config": {}
            }
        },
        {
            "type": "Microsoft.Web/sites/functions",
            "apiVersion": "2018-11-01",
            "name": "[concat(variables('fetchSciHubProductURLName'), '/UploadFilesToAzureStorage')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', variables('fetchSciHubProductURLName'))]"
            ],
            "properties": {
                "script_root_path_href": "https://testqwe123.azurewebsites.net/admin/vfs/home/site/wwwroot/UploadFilesToAzureStorage/",
                "script_href": "https://testqwe123.azurewebsites.net/admin/vfs/home/site/wwwroot/bin/DemoThirdPartyDataDownload.AzFunction.dll",
                "config_href": "https://testqwe123.azurewebsites.net/admin/vfs/home/site/wwwroot/UploadFilesToAzureStorage/function.json",
                "href": "https://testqwe123.azurewebsites.net/admin/functions/UploadFilesToAzureStorage",
                "config": {}
            }
        }

I have problem with below types, Microsoft.Web/sites/functions When I check in this code, both Microsoft.Web/sites/functions fails. It throws me below error.

{
    "Code": "BadRequest",
    "Message": "Encountered an error (InternalServerError) from host runtime.",
    "Target": null,
    "Details": [
        {
            "Message": "Encountered an error (InternalServerError) from host runtime."
        },
        {
            "Code": "BadRequest"
        },
        {
            "ErrorEntity": {
                "Code": "BadRequest",
                "Message": "Encountered an error (InternalServerError) from host runtime."
            }
        }
    ],
    "Innererror": null
}

spent couple of hours to figure it out and still not finding it. Can someone help me what I am doing wrong here? Any help would be really helpful Thanks

Working with ARM templates is oftentimes infuriating. For debugging, I recommend the following strategy. To get things working, skip deploying through any kind of devops pipeline. Instead, deploy straight through Visual Studio through an ARM project.

Next, strip the template down to a single resource, and get that resource working. This may involve stripping the resource template itself down to its bare minimum to get it working, then add attributes back one by one until you figure out what is breaking.

In your example above, I'd start with the "fetchSciHubProductURLName" resource.

Deploying from Visual Studio has the advantage of validating the template before deployment, and you may get better error messages that way.

Also as a handy resource, the ARM template schema is published here . There's also schemas for other ARM resources as well.

It's not actually clear in the documentation but bindings are required and the error is rubbish as gives no hint as to what the issue is, just 'Internal Server Error'....

Example: Function Quick Start Template

Required Example (Bicep):-

config: {
      bindings: [
        {
          name: 'req'
          type: 'httpTrigger'
          direction: 'in'
          authLevel: 'function'
          methods: [
            'get'
          ]
        }
      ]
    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM