Skip to main content

Create and Run an Azure Function Locally Using Azure Functions Core Tools

Hands-On Lab

 

Photo of

Training Architect

Length

00:45:00

Difficulty

Intermediate

In this hands-on lab, we use a Windows VM and Azure Functions Core Tools to create and run an Azure Function on that VM.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Create and Run an Azure Function Locally Using Azure Functions Core Tools

Introduction

In this hands-on lab, we use a Windows VM and Azure Functions Core Tools to create and run an Azure Function on that VM.

Scenario

You are on an interview and asked to demonstrate your knowledge of Azure Functions Core Tools. You're asked to create a .NET Core functions project on a development, then add an HTTP-triggered function to the project, and run the function app on the development system. You will not get hired if you can't accomplish this task.

Log In to the Azure Portal

  1. Log in to the Azure Portal using the credentials provided on the lab instructions page.

Remote into the Windows VM

  1. Open the menu in the top-left corner and select All resources.

  2. Click lab-VM.

  3. Copy the Public IP address to the clipboard.

  4. Open Remote Desktop Connection.

  5. Paste the IP address into the Computer field of the Remote Desktop Connection window.

  6. Click Connect.

  7. In the authentication window, click More choices.

  8. Select the option for Use a different account.

  9. Provide a user name of cloud_user and a password of Azure!Funcs!VM in the credentials window.

  1. Click OK.

  2. If prompted to accept the certificate, click Yes.

Install Azure Functions Core Tools

  1. Click the Start Menu and right-click on Windows PowerShell ISE.

  2. Select Run as administrator.

  3. Click the new document button to open a new document.

  4. Paste the following commands into the top section of the PowerShell ISE window.

    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
  5. If a pop-up pane appears on the side, close it.

  6. Run the commands by pressing F5 or the Run Script button in the ribbon.

  7. Close the PowerShell ISE.

Create the Azure Functions Project

  1. Open a command prompt.

  2. Verify that Azure Functions Core Tools is installed.

    func
  1. Create a new directory and transition to it.

    mkdir myfunc
    cd myfunc
    1. Initialize a new function.
    func init
    1. Select dotnet from the possible options.

Create the Azure Function

  1. Add a new function.

    func new
  2. Select HttpTrigger from the possible options.

  3. Give it a name of "MyHttpFunction" (without the quotes) when prompted.

  4. Verify the project stucture.

    dir

Run the Function App

  1. Run the app.

    func start

Invoke the Function

  1. Start PowerShell as administrator from the Start Menu.

  2. Execute the function in the PowerShell prompt.

    Invoke-WebRequest -Uri http://localhost:7071/api/MyHttpFunction?name=Mike -UseBasicParsing
  1. Verify that the function runs in the original command prompt and provides output in the PowerShell prompt.

Conclusion

Congratulations, you've completed this hands-on lab!