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

How to Deploy Azure Functions

By - Source: Toms IT Pro

How your company deploys Azure functions depends on your company’s needs, but these tips should help you decide.

Azure Functions is just a collection of scripts or binaries hosted on the Azure Web App platform. They can be deployed in multiple ways, and no one can tell you which will be the best fit for your organization. That is a broader question that involves more than just technology. But this will hopefully assist you in a decision as to which deployment model best suits your needs.

MORE: Windows 10 for IT Pros: Tutorials, Tips & Tricks

Azure Functions File System

Before we dive into the setup of those methods a quick explanation of what an Azure Function is, from a File System's perspective. We can check the Function App's content in the Azure Portal by expanding our Function pane to the right to select "View Files."

We can see the very basic setup of an Azure Function. The "definition" is stored in the "function.json" file and the actual code resides in "run.csx" (or whatever extension the language of your choice uses). Plus, each Function has its own directory. Whatever deployment method you will choose, this is the very basic folder structure your Function requires.

Continuous Deployment

Explaining Continuous Deployment (CD) fills books, but here is the quick explanation in the context of Azure Functions. Every time we update our Function, our code, in our local source code repository (e.g. git, Github, Bitbucket) and we commit those changes, a trigger executes and causes Azure to check the new code and update the Functions accordingly, if needed, automatically.

CD is code that is deployed as soon as the person writing that code feels it is ready to go. The assumption is that you have got your code in a Githubrepository. You can use other Source Control systems, but Github seems to be the most popular around.

To create the link between your Azure Function App and your Github repository, log on to the Azure Portal and navigate to your Function App.

Select the Function App's Platform Features and find the "Deployment Options" link.

The next pane ("Deployments") opens and for our demo Function App this pane should not have any content yet. Only the "Setup" button at the top of the pane should be available to us. This will bring us to the pane where we set up the link between our Source Control repository and Azure. After going through the authentication on Github, and selecting the appropriate repository and branch, we can save the configuration.

The next step should only take about 30 seconds for our demo Function. Azure will clone the repository and copy the code into the correct location on Azure Web App (conveniently abstracted away). Navigate back to the Function to see that this is now read-only. This is part of "Only one path to Production" and this path is now through our Source Control repository.

Make a change to the code, commit it to your repository and push it online. Wait a few seconds and check your Function. It will reflect the change shortly after your "git push."

In a real workflow, you would have multiple Function Apps that could be configured to be deployed from a "development", a "QA" and a "master" branch on your repository. That way you can deploy code into different environments, and you do not have to commit your code straight to master that risks breaking your application.

Azure Functions CLI

Azure Functions comes with its own Command Line Interface (CLI) which is available to install via "npm." This CLI is very handy for local development of Azure Functions as it can run a local Azure Function Application, which is plain awesome. You can write and test your Functions locally.
However, you can also deploy locally developed Functions from your laptop to Azure. A basic workflow can be found here.

The CLI needs to login to your subscriptions, same as the PowerShell Module or the Azure CLI and you will need to select the correct subscription, if applicable. "func init" will create some boilerplate in the current working directory, and the publish command uploads the code to Azure that will then extract it to the correct location.

The CLI does not require a lot of setup, but greatly assists in the development of Functions locally and management of Functions already published on Azure.

I encourage you to check out other options for both the Continuous Deployment integration and the Azure Functions CLI, as these are both very powerful tools when it comes to Azure Functions development.