Using Azure Functions with C#

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

In this lab, you will gain experience using C#, Visual Studio, and Azure Functions. You will build an Azure function using C# code that is triggered by a webhook and saves data to Azure Table storage using a Table storage binding. You will then run a console application to see everything working and will verify that table data was saved using Azure Storage Explorer. Finally, you will check the Azure portal to ensure telemetry data was saved to Application Insights. Upon completion of the lab, you will have gained the experience required to work with Azure Functions using C#.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create Function and Application Insights in the Azure Portal
  1. Review the lab-provisioned resources.
  2. Take note of the resource group location and the 5 character suffix for all of the deployed resources. These will be used later in the lab.
  3. Create a new function app.
  4. Once deployed, enable Application Insights.
RDP into the VM, Configure Storage Explorer, and Open the Visual Studio Solution
  1. Download the RDP file for the lab-provided VM.
  2. Connect to the VM, clone the Azure labs repository, and extract from it the solution file for the lab.
  3. Download and install Azure Storage Explorer.
  4. Configure storage explorer using resources created in the lab.
  5. Open the extracted solution file to start Visual Studio.
Update and Run Visual Studio Solution, Verify Table Data using Storage Explorer, and Verify Application Insights Data
  1. Using Visual Studio, update the local.settings.json and Functions1.cs files with information copied during previous lab objectives as well as the following code:

    public static class Function1
    {
        [FunctionName("Function1")]
        [return: Table("<TABLE_NAME>", Connection = "StorageConnectionAppSetting")]
        public static SampleData Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
            HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
    
            string name = req.Query["name"];
    
            return new SampleData()
            {
                PartitionKey = "Http",
                RowKey = Guid.NewGuid().ToString(),
                Text = name
            };
        }
    }
    
    public class SampleData : TableEntity
    {
        public string Text { get; set; }
    }
  2. Run the updated function.

  3. Using a web browser, test the updated function.

  4. Verify the data is stored in the table successfully using Azure Storage Explorer.

  5. Review the telemetry data using Application Insights.

Additional Resources

As a developer, you want to use the Azure SDK and C# code, to create and invoke an Azure function.

To do this, you will RDP into a virtual machine in Azure, download a pre-built solution, and fill in the correct C# code to get the function to compile. When you run the function, it will be invoked using a webhook, and it will save data to Azure Table using a Table storage binding. You will also log data to the trace and log telemetry to Application Insights, which you will verify through the Azure portal.

This lab gives step-by-step instructions for each task. Follow along with those, and you will have successfully created and invoked an Azure function.

You are the application developer for Show Me The Way, a shipping logistics company located in London.

You will need to:

  • Create an Azure Function App.
  • Enable Application Insights on an Azure Function App.
  • Use Visual Studio to execute function code.
  • Verify data and telemetry being produced by the function.

If you get stuck, feel free to check out the solution video, or the detailed instructions under each objective. Good luck!

Tools

To complete many of the lab objectives you will be using the Azure Portal. You can access the portal by clicking here.

You will use Azure Storage Explorer to view the contents of table storage. This can be downloaded here.

We will be using RDP to access our Windows virtual machines in this lab. For MacOS and Linux workstations, you may need to download an RDP application in order to connect to these virtual machines:

Lab Suffix

Pre-deployed lab resources will all end with a unique five-character suffix. Make note of this suffix, as you may need it when naming resources during the lab.

WARNING: Be Prepared for UI Changes

Given the fluid nature of Microsoft cloud tools, you may experience user interface (UI) changes that were made following the development of this hands-on lab that do not match up with lab instructions. When any such changes are brought to our attention, we will attempt to update the content accordingly. However, if changes occur, students will have to adapt to the changes and work through them in the hands-on labs as needed.

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?