Deploy a Function Created with Azure Functions Core Tools to Azure

45 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we will build an Azure Function app on a Windows VM and then publish it to an Azure Function app service within Azure. We will do this all using Azure Functions core tools.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log In to the Azure Portal

Log in to the Azure Portal using the username and password supplied by the lab.

  1. Open a browser.
  2. Navigate to the provided Azure Portal URL.
  3. Use the supplied username and password to authenticate.
Remote into the Windows VM

Starting in the Azure dashboard, perform the following tasks:

  1. Open the navigation menu in the upper-left of the Portal.
  2. Click on All resources.

Wait for the the list of all resources appear.

In the list, click on the lab-VM resource.

Wait for the VM overview page to open. On that page, make note of the public IP address.

Using a remote desktop client, connect to the IP address of the VM. Log in using the following credentials:

  • Username: cloud_user
  • Password: Azure!Funcs!VM

Accept the certificate if asked to do so.

Wait patiently for the desktop to load and stabilize, then click No for network sharing and close the server manager if it opens.

Install Azure Functions Core Tools

Open PowerShell ISE as an administrator. Open a new script window. Paste the following into the editor window, not the blue pane.

choco install nodejs-lts -y --force
npm i -g azure-functions-core-tools@3 --unsafe-perm true
code --install-extension ms-vscode.csharp
code --install-extension ms-vscode.azurecli
code --install-extension ms-azuretools.vscode-azurefunctions
code --install-extension ms-vscode.azure-account
code --install-extension ms-azuretools.vscode-azurestorage
code --install-extension ms-vscode.powershell

Run the script by pressing F5 or the play button.

Wait for a few minutes for it to complete.

Close the PowerShell ISE window.

Open the Source Code in Visual Studio Code

Open an administrative command prompt. Change to the directory with the code using the following command:

cd codedeploy

Now open the project in Visual Studio Code with the following command:

code .

Wait for Visual Studio Code to open the solution.

On the toast message about detecting an Azure Functions project being found in the folder, press the Yes button.

On the toast message about There are unresolved dependencies…, click the Restore button.

Build, Deploy, and Test the Function App

In Visual Studio Code, open the deploy.ps1 file in the project. We will execute commands in this script one-by-one. Each line of the script can be individually executed by selecting the line and pressing F8.

First, change the directory. While this is not required, it’s good practice.

cd codedeploy

Build the solution:

dotnet build

Log in to Azure with the Azure CLI. This is very important.

az login

This will pop-up Internet Explorer for logging in. On the nag screen about security, select the default option. A tab will open with a log in form, but another tab will open on top welcoming you to IE – close that one.

Back in the login form, log in using the credentials previously used to log into Azure, not the credentials to log into the VM.

The terminal window in VS Code will show some JSON indicating a successful login.

Now get the function app name by running the following PowerShell / Azure CLI:

$name = $(az functionapp list --query "[0].name" -o tsv)
$name

And now deploy the function app to Azure with the following Azure Core Function Tools commmand:

func azure functionapp publish $name --csharp --force

This will take several minutes. When complete, the system provides a URL by the output of the deployment. Copy that URL to the clipboard.

Go back to the Azure Portal in the browser. Go to the overview of the function app. This will be in the All resources list as an app service with a name starting with fa-. This is also seen as ouput of the above command to get the function app name.

From the function app overview, refresh the view of the function app in the tree on the left side. Click on the function named MyHttoFunction.

This shows the open file function.json.

On the left of the browser page, click on Test. Wait for the panel to open.

In the query section, click + Add parameter, and add a parameter name. Enter a value without spaces or special characters.

Go to the bottom of the panel and press the Run button. In a moment, the output will show a Status: 200 OK message above the Run button if everything worked.

Additional Resources

You're an Azure Functions developer in your organization. You need to deploy an Azure Function application that you're developing on your dev system to an Azure Function App service in your employers Azure Account. This is necessary so your customers can use the functions in the app. The users of your function will be very unhappy if you do not get the deployment completed.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?