Deploy Azure Function with ARM template

microsoft.web/sites arm template
azure functions quickstart
arm template resource group
azure functions arm template reference
arm template parameters file
deploy azure function from github
learn azure arm templates
deploy azure function cli

I am trying to deploy Azure Function with ARM template , but I am not able to create the function itself. Is it possible to create the actual function using ARM template?

I have zipped the source code for the function and placed it in a public location, I have added the MSBuild section to the template and although the deployment finished successfully - the App function was created but not the function itself

here is the template

{
"parameters": {
    "name": {
        "type": "string"
    },
    "storageName": {
        "type": "string"
    },
    "location": {
        "type": "string"
    },
    "subscriptionId": {
        "type": "string"
    },
    "storage_account_endpoint": {
        "type": "string"
    }
},
"resources": [
    {
        "apiVersion": "2016-03-01",
        "name": "[parameters('name')]",
        "type": "Microsoft.Web/sites",
        "properties": {
            "name": "[parameters('name')]",
            "siteConfig": {
                "appSettings": [
                    {
                        "name": "FUNCTIONS_WORKER_RUNTIME",
                        "value": "node"
                    },
                    {
                        "name": "AzureWebJobsStorage",
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                    },
                    {
                        "name": "FUNCTIONS_EXTENSION_VERSION",
                        "value": "~2"
                    },
                    {
                        "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                    },
                    {
                        "name": "WEBSITE_CONTENTSHARE",
                        "value": "[concat(toLower(parameters('name')), 'bd58')]"
                    },
                    {
                        "name": "WEBSITE_NODE_DEFAULT_VERSION",
                        "value": "8.11.1"
                    },
                    {
                        "name": "storage_account_connection",
                        "value": "[parameters('storage_account_endpoint')]"
                    }
                ]
            },
            "clientAffinityEnabled": false,
            "reserved": false
        },
        "dependsOn": [
            "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
        ],
        "resources": [
            {
                "name": "MSDeploy",
                "type": "Extensions",
                "apiVersion": "2015-02-01",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
                ],
                "properties": {
                    "packageUri": "<URL to zip>"
                }
            }
        ],
        "location": "[parameters('location')]",
        "identity": {
            "type": "SystemAssigned"
        },
        "kind": "functionapp"
    },
    {
        "apiVersion": "2015-05-01-preview",
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[parameters('storageName')]",
        "location": "[parameters('location')]",
        "properties": {
            "accountType": "Standard_LRS"
        }
    }
],
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0"
}

In short No - ARM can only create the infrastructure for you but not deploy the code (**see comment). But as always there is a way. A while back MS release a new feature 'Run from ZIP' on web apps (including Function Apps). All you need is the actual project (code published as ZIP) to be in a location where the function app can access it.

We use VSTS (Azure Dev Ops) for CI/CD. So we build the solution add the ZIP to the artifact. Then in the Release we copy the ZIP to blob storage, create a SAS Token and pass the location of the blob Container with the SAS Token to ARM. In the ARM template we build the connection string to the ZIP, using input parameter. As soon as ARM is done then the Function is up and running.

Eg.

{ 
"parameters": {
"name": {
    "type": "string"
},
"storageName": {
    "type": "string"
},
"location": {
    "type": "string"
},
"subscriptionId": {
    "type": "string"
},
"storage_account_endpoint": {
    "type": "string"
},
 "artifactsUri": {
  "type": "string"
},
"artifactsBlobContainer": {
  "type": "string"
},    
"artifactsLocationSasToken": {
  "type": "string"
}
},
"resources": [
{
    "apiVersion": "2016-03-01",
    "name": "[parameters('name')]",
    "type": "Microsoft.Web/sites",
    "properties": {
        "name": "[parameters('name')]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "FUNCTIONS_WORKER_RUNTIME",
                    "value": "node"
                },
                {
                    "name": "AzureWebJobsStorage",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                },
                {
                    "name": "FUNCTIONS_EXTENSION_VERSION",
                    "value": "~2"
                },
                {
                    "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                    "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
                },
                {
                    "name": "WEBSITE_CONTENTSHARE",
                    "value": "[concat(toLower(parameters('name')), 'bd58')]"
                },
                {
                    "name": "WEBSITE_NODE_DEFAULT_VERSION",
                    "value": "8.11.1"
                },
                {
                    "name": "storage_account_connection",
                    "value": "[parameters('storage_account_endpoint')]"
                },
                {
                  "name": "WEBSITE_RUN_FROM_ZIP",
                  "value": "[concat(parameters('artifactsUri'), '/', parameters('artifactsBlobContainer'),'/','blahbla.FA.zip',parameters('artifactsLocationSasToken'))]"
                }
            ]
        },
        "clientAffinityEnabled": false,
        "reserved": false
    },
    "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
    ],
    "resources": [
        {
            "name": "MSDeploy",
            "type": "Extensions",
            "apiVersion": "2015-02-01",
            "dependsOn": [
                "[resourceId('Microsoft.Web/Sites', parameters('name'))]"
            ],
            "properties": {
                "packageUri": "<URL to zip>"
            }
        }
    ],
    "location": "[parameters('location')]",
    "identity": {
        "type": "SystemAssigned"
    },
    "kind": "functionapp"
},
{
    "apiVersion": "2015-05-01-preview",
    "type": "Microsoft.Storage/storageAccounts",
    "name": "[parameters('storageName')]",
    "location": "[parameters('location')]",
    "properties": {
        "accountType": "Standard_LRS"
    }
}
],
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0"
}

'Run from ZIP' is achieved with the 'WEBSITE_RUN_FROM_ZIP' app setting. Hope this helps

Azure Resource Manager (ARM) Templates, Deployment functions for ARM templates. 04/27/2020; 5 minutes to read. In this article. deployment; environment; parameters; variables; Next steps. Resource  An ARM template is a JSON file that describes our architecture. To deploy an Azure Function we need at least three recourses: a functionApp, a service plan, and a storage account. The FunctionApp is, of course, our function. The service plan could be set as dynamic or describe the type of resource that will be used by your function.

I just use this FunctionWebDeploy.json template. I download the app content(zip file)from the existing function app and upload it to the public address. Finally I can deploy function app including code.

Templates overview, Azure Resource Manager (ARM) templates are JSON files that describe the state of a resource group. They typically declare the full set of  You can use an Azure Resource Manager template to deploy a function app. This article outlines the required resources and parameters for doing so. You might need to deploy additional resources, depending on the triggers and bindings in your function app.

  1. Go to Azure portal portal.azure.com, and create a new Azure Function.

2.Go to Resource Group. 3.Go to Export template. 4.You will see something like this.

This is the ARM Template for all resources/componets.

This post will describe the ARM template used to simplify deployment of the Azure resources required to get you started with Azure Functions  One of the biggest benefits of the model is the definition of your resources, dependencies, and overall deployment of related resources can be defined in an Azure Resource Manager (ARM) Template. A simple JavaScript Object Notation (JSON) file used to define the infrastructure, dependencies, configuration properties, tags, access control and policies for your resource group.

An ARM template is a JSON file that describes our architecture. To deploy an Azure Function Duration: 13:38 Posted: Jul 19, 2019 In general, the role of ARM templates is typically to deploy the infrastructure required for an application, while the deployment of the actual application logic happens separately. However, Azure Functions’ ARM integration has a feature whereby an ARM template can be used to deploy the files required to make the function run.

Although I don't particularly enjoy creating Azure Resource Manager (ARM) templates, A list of names for the Azure function apps to deploy. I am trying to deploy Azure Function with ARM template , but I am not able to create the function itself. Is it possible to create the actual function using ARM template? I have zipped the source code for the function and placed it in a public location, I have added the MSBuild section to the template and although the deployment finished

To get started, you can use the below azuredeploy.json as an example: Another way you can deploy a function using ARM template is by  Today I came across a request around how can you deploy your Azure Functions using ARM templates. As someone who always likes a challenge I thought I’d dust off my template skills and see if we could come up with something.

Comments
  • Did you zip the folder of your code, and not just the contents? See mythoughtlab.azurewebsites.net/azure/…
  • yes - this is exactly what I did
  • arm templates can deploy code for you if you put the code inline in a files:{...} field
  • But how do you ensure security if the uploaded zip file is accessible publicly? I'm assuming you are uploading to storage space and using a url to access it publicly.