Product and service reviews are conducted independently by our editorial team, but we sometimes make money when you click on links. Learn more.
 

Alternative Azure Function Deployment

By - Source: Toms IT Pro

You can deploy Azure Functions using Visual Studio or Azure Resource Manager templates. Here's how.

Beyond CLI and Continuous Deployment, you can deploy Azure Functions through Visual Studio or VS Code, or Azure Resource Manager (ARM) templates. These are used for the deployment of solutions or for integrated solutions where the Azure Function is not deployed by itself.

MORE: How to Deploy Azure Functions

Visual Studio and VS Code

In the .net ecosystem Visual Studio has always been the de-facto standard development environment so most developers will already be quite familiar with Visual Studio.


VS Code is a recent integrated development environment with a big fan base in the open source community.

Both know how to handle Azure Functions, so it comes down to your personal preference which one to choose. I will start with Visual Studio as this has the "more complete" experience.

Microsoft, at their recent Build conference, announced and released their new Azure Functions tools for Visual Studio 2017, and that there will not be any updates to the existing Azure Functions tools for Visual Studio 2015. This means that one must install Visual Studio 2017, and rely on "Update 3," which is still in beta. Visual Studio 2017 now supports side-by-side beta installations, so give it a go if you can.

The new tools support C# compiled libraries (.dll), and have quite a few advantages over Microsoft's initial approach to C# via CSX (C# script files). For example, the time to launch the runtime environment the first time is considerably less (cold start) compared to CSX, plus Visual Studio supports intellisense, unit testing and all the other nice things, such as local debugging using the "compiled C# Azure Functions".

To get started, download the Azure Function tools for Visual Studio 2017 Update 3 (or later) and install them. Next launch of Visual Studio we can now create a new project of type "Azure Functions." For now, this only supports C#. Plans for other languages exist on the roadmap.

This will create an empty function with some boilerplate code describing the Function App which should be familiar from the previous article. In the context of this article we can ignore those files. 
Right-click on the project we will "Add an Item" to the project of template type "Azure Function".

We want to trigger our function from an event in an Azure Storage Queue, so we will pick the "QueueTrigger" template. Filling in the required information, we give our Function a name and the name of the environment variable holding the connection string to the Storage Queue, plus the actual name of the queue.


By default, every Function App creates a Storage Account, so let's just go ahead and use the variable called "AzureWebJobsStorage" as the connection value. This is the easiest setup.

Click create, and our C# function will be triggered whenever something happens in our Storage Queue.

We can right-click our project, and select "Publish," which will guide us through a dialogue to select either an existing or a new Azure Function App as a target. I will select the existing Function App and click "publish". A few seconds later we can check the Azure portal and see our new Function waiting for input.

As a test, we can create a message in our Storage Queue. The Azure Storage Explorer app comes in really handy here. Use it to connect to your Azure Subscription and interact with all your Storage Accounts. Find the correct Storage Account associated with our Function App and right-click the Queue to create a queue, name it "myqueue." You can send a message to it, and double check by looking at the Function's log output.

Azure Resource Manager templates

With Azure's move to Azure Resource Manager (ARM) came a new way of doing deployments to Azure in the form of templates written in JSON (JavaScript Object Notation).

These templates describe in a declarative fashion the end state of your environment, as in what resources you want to have deployed and how you want them to be configured. You do not necessarily describe how you want to deploy these resources as this logic is embedded into the underlying fabric. This includes error handling, and, in most cases, also idempotence, and built-in capability to update already existing resources or stacks with new versions.

This deployment method is probably best for stacks or applications with multiple types of resources, such as an application requiring an HTTPS endpoint, an Azure Function, Azure VM, Storage Accounts and a CosmosDB. We do not want to deploy each resource on its own but rather treat it as a full stack deployed as one thing. No better way than to use one ARM template for this.

In Visual Studio, we can create a new project of type "Azure Resource Group" and search for "functions" in the Azure Quickstart templates report. This will pull up a template on GitHub that we can deploy into our Visual Studio environment.

From Visual Studio now we can right-click the project and choose "Deploy" to get this code live and create a new Storage Account, a hosting Plan (dynamic/consumption based in this case) and a Function App.

Comments