Reader small image

You're reading from  Azure Serverless Computing Cookbook. - Third Edition

Product typeBook
Published inJun 2020
PublisherPackt
ISBN-139781800206601
Edition3rd Edition
Concepts
Right arrow
Author (1)
Praveen Kumar Sreeram
Praveen Kumar Sreeram
author image
Praveen Kumar Sreeram

Praveen Kumar Sreeram is an author, Microsoft Certified Trainer, and certified Azure Solutions Architect. He has over 15 years of experience in the field of development, analysis, design, and the delivery of applications of various technologies. His projects range from custom web development using ASP.NET and MVC to building mobile apps using the cross-platform Xamarin technology for domains such as insurance, telecom, and wireless expense management. He has been given the Most Valuable Professional award twice by one of the leading social community websites, CSharpCorner, for his contributions to the Microsoft Azure community through his articles. Praveen is highly focused on learning about technology, and blogs about his learning regularly. You can also follow him on Twitter at @PrawinSreeram. Currently, his focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core.
Read more about Praveen Kumar Sreeram

Right arrow

4. Developing Azure Functions using Visual Studio

In this chapter, we'll cover the following:

  • Creating a function application using Visual Studio 2019
  • Debugging Azure Function hosted in Azure using Visual Studio
  • Connecting to the Azure Storage from Visual Studio
  • Deploying the Azure Function application using Visual Studio
  • Debugging Azure Function hosted in Azure using Visual Studio
  • Deploying Azure Functions in a container

Introduction

In previous chapters, you learned how to create Azure Functions right from the Azure Management portal. Here are a few of the features that we encountered:

  • We can quickly create a function just by selecting one of the built-in templates provided by the Azure Functions runtime.
  • Developers need not worry about writing plumbing code or understanding how to work with the frameworks.
  • Configuration changes can be made right within the UI using the standard editor.

Despite the advantages provided by the Azure Management portal, moving over from a familiar integrated development environment (IDE) to something new can prove to be a daunting task for developers. To ease this transition, the Microsoft team has come up with a few tools that help developers to integrate Azure Functions into Visual Studio, with the aim of leveraging critical IDE features that are imperative for accelerating development efforts. Here are a few of the features:

  • Developers...

Creating a function application using Visual Studio 2019

In this recipe, you will learn how to create an Azure function in Visual Studio 2019 with the latest available Azure Functions runtime. You'll also discover how to provide access to anonymous users.

Getting ready

You'll need to download and install the following tools and software:

  • Download the latest version of Visual Studio 2019, which can be found here: https://visualstudio.microsoft.com/downloads/
  • During the installation, choose Azure development in the Workloads section and then click on the Install button.

How to do it…

In this section, you'll create a function application and a HTTP function using Visual Studio by performing the following steps:

  1. Open Visual Studio, choose Create a new project, select Azure in the platform dropdown, and then choose the Azure Functions template. Once you are ready, click on Next, as shown in Figure 4.1:
    Choosing the Azure Functions template for creating the project
    Figure 4.1: Create a new project...

Debugging Azure Function hosted in Azure using Visual Studio

Once the basic setup of your Function creation is complete, the next step is to start working on developing the application as per your needs. Developers end up facing numerous technical issues that require tools to identify the root cause of the problem and fix it. These tools include debugging tools that help developers to step into each line of the code to view the values of the variables and objects and get a detailed view of the exceptions.

Getting ready

Download and install the Azure CLI (if these tools are not installed, Visual Studio will automatically download them when you run your functions from Visual Studio).

How to do it...

In this section, you'll learn how to configure and debug an Azure function in a local development environment within Visual Studio.

Perform the following steps:

  1. In the previous recipe, you created the HTTP trigger function using Visual Studio. Let's build...

Connecting to the Azure Storage from Visual Studio

In both of the previous recipes, you learned how to create and execute Azure Functions in a local environment. You triggered the functions from a local browser. However, in this recipe, you'll learn how to trigger an Azure function in your local environment when an event occurs in Azure. For example, when a new blob is created in an Azure storage account, we can have our function triggered on our local machine. This helps developers to test their applications upfront, before deploying them to the production environment.

Getting ready

Perform the following steps:

  • Create a storage account, and then a blob container named cookbookfiles, in Azure.
  • Install Microsoft Azure Storage Explorer from http://storageexplorer.com/.

How to do it...

In this section, you'll learn how to create a blob trigger that will trigger as soon as a blob is created in the storage account.

Perform the following steps...

Deploying the Azure Function application using Visual Studio

So far, your function application is just a regular application within Visual Studio. To deploy the function application along with its functions, you need to either create the following new resources, or select existing ones to host the new function application:

  • The resource groups
  • The App Service plan
  • The Azure Function application

You can provide all these details directly from Visual Studio without opening the Azure Management portal. You'll learn how to do that in this recipe.

How to do it…

In this section, you'll learn how to deploy Azure Functions to Azure.

Perform the following steps:

  1. Right-click on the project and then click on the Publish button to open the Pick a publish target dialog box.
  2. In the Pick a publish target dialog box, choose the Create New option and click on the Create Profile button, as shown in Figure 4.20:
    Publishing and deploying the Azure function app using Visual Studio
    Figure 4.20: Visual Studio—...

Debugging Azure Function hosted in Azure using Visual Studio

In one of the previous recipes, Connecting to the Azure Storage from Visual Studio, you learned how to connect a storage account from the local code. In this recipe, you'll learn how to debug the live code running in the Azure cloud environment. You'll perform the following steps in the BlobTriggerCSharp function of the FunctionAppinVisualStudio function application:

  • Change the path of the container in the Azure Management portal to that of the new container.
  • Open the function application in Visual Studio 2019.
  • Attach the debugger from within Visual Studio 2019 to the required Azure function.
  • Create a blob in the new storage container.
  • Debug the application after the breakpoints are hit.

Getting ready

Create a container named cookbookfiles-live in the storage account. You'll be uploading a blob to this container.

How to do it…

In this recipe, you'll make the...

Deploying Azure Functions in a container

You have now seen some of the major use cases for Azure Functions—in short, when developing a piece of code and deploying it in a serverless environment, where a developer or administrator doesn't need to worry about the provisioning and scaling of instances to host server-side applications.

Note

You can take advantage of all the features of serverless (for example, autoscaling) only when you create your function application by choosing the Consumption plan in the Hosting Plan drop-down menu.

By looking at the title of this recipe, you might already be wondering why and how deploying an Azure function to a Docker container will help. Yes, the combination of Azure Functions and Docker containers might not make sense, as we would lose all the serverless benefits (for example, autoscaling) of Azure Functions if we deployed to Docker.

However, there may be some customers whose existing workloads might be in a cloud (be it...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Azure Serverless Computing Cookbook. - Third Edition
Published in: Jun 2020Publisher: PacktISBN-13: 9781800206601
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Praveen Kumar Sreeram

Praveen Kumar Sreeram is an author, Microsoft Certified Trainer, and certified Azure Solutions Architect. He has over 15 years of experience in the field of development, analysis, design, and the delivery of applications of various technologies. His projects range from custom web development using ASP.NET and MVC to building mobile apps using the cross-platform Xamarin technology for domains such as insurance, telecom, and wireless expense management. He has been given the Most Valuable Professional award twice by one of the leading social community websites, CSharpCorner, for his contributions to the Microsoft Azure community through his articles. Praveen is highly focused on learning about technology, and blogs about his learning regularly. You can also follow him on Twitter at @PrawinSreeram. Currently, his focus is on analyzing business problems and providing technical solutions for various projects related to Microsoft Azure and .NET Core.
Read more about Praveen Kumar Sreeram