Exercise - Publish a simple Azure Function

Completed

The Publish wizard in the Azure Functions template provides the most straightforward way to deploy Azure Functions, especially for testing purposes.

In the luxury watch online website scenario, you decided to use Visual Studio 2022 to deploy functions to an Azure Function App in the cloud. First, you create an Azure Function App, and then use the Visual Studio Publish wizard to deploy the functions you create.

Here, you use the Azure portal to create an Azure Function App. Then, you deploy the WatchInfo function using the Visual Studio project that you created in a previous exercise. Lastly, you verify that your function is correctly deployed by testing it.

Create an Azure Function App using the Azure portal

  1. Sign into the Azure portal using the same account you used to activate the sandbox.

  2. From the resource menu or the Home page, select Create a resource.

    Screenshot of Azure portal menu and Create a resource option.

    The Create a resource pane appears.

  3. In the Create a resource menu, select Compute, and then search for and select Function App. Select Create.

    Screenshot of Compute category and Function App service option.

    The Create Function App pane appears.

  4. On the Basics tab, enter the following values for each setting.

    Note

    Your function app must have a name unique to Azure. We suggest using something like <your initials>watchfunctions. Use this name wherever you see <your-function-app-name> in the remainder of the exercise.

    Setting Value
    Project Details
    Subscription Concierge Subscription
    Resource Group From the dropdown list, select [Sandbox resource group].
    Instance Details
    Function App name <your-function-app-name>
    Publish Code
    Runtime stack .NET
    Version 6
    Region Accept the default location.
    Operating system
    Operating System Windows
    Plan
    Plan type Consumption (Serverless)
  5. Select Next : Storage.

  6. On the Storage tab, enter the following values for each setting.

    Setting Value
    Storage
    Storage account Accept the default value.
  7. Select Review + create, and then select Create. The deployment shows the resources that are created for the Function App.

  8. When deployment completes, select Go to resource. The Function App pane for <your-function-app-name> appears.

Deploy the WatchInfo function to the Azure Function App

  1. On your desktop, return to Visual Studio.

  2. In the Solution Explorer window, right-click the WatchPortalFunction project, and then select Publish.

    Screenshot of Visual Studio, showing the Publish option for the WatchPortalFunctions project.

    The Publish pane appears.

  3. Select Azure, and then select Next.

    Screenshot of the Publish target window with the Azure option highlighted.

    The Publish pane updates with the new information.

  4. Select Azure Function App (Windows), then select Next.

    Screenshot of the Publish specific target window with the Azure Function App (Windows) option highlighted.

  5. In the Subscription name dropdown list, select Concierge Subscription. Expand the [Sandbox resource group] folder, then select your Function App. Select Finish.

    Screenshot of the Publish Functions instance window. The user to select Function Apps.

  6. Select Publish.

    [Screenshot of Visual Studio highlighting Finish.

    Wait for your functions to be deployed. The Output window in Visual Studio shows the progress of the build and publish processes. If everything works, you should have one successful Build and one successful Publish.

    Screenshot of the Output window in Visual Studio. The output messages indicate that the functions were published successfully.

Verify the functions are deployed

  1. Return to the Azure portal. The Function App pane appears with your function app.

  2. In the Function App menu, under Functions, select Functions. The Functions pane appears for your function app.

  3. Verify that the Function1 and WatchInfo functions are listed.

  4. In the Function App menu, select Overview and check that the Status of the Azure Function App is listed as Running.

    Screenshot of the Azure portal Function App pane showing the 'Function1' and 'WatchInfo' functions.

    Note

    The functions are marked as Read Only. You cannot modify their settings or configuration from the Azure portal because you published them from Visual Studio. If you need to update either of these functions, make the changes in Visual Studio and publish them again.

  5. In the Function App pane, select the URL (highlighted in the previous image). A browser window opens, and confirms that the function app is up and running.

    Screenshot of a web browser showing the function app is running.

  6. Append the URL of the WatchInfo function, /api/watchinfo, to the URL in the browser to invoke the WatchInfo function without a query string. You might need to refresh the browser to see the error message Please provide a watch model in the query string.

    Screenshot of web browser window showing the error message.

  7. Add the query string ?model=abc to the URL and refresh the browser window. This time, you see the details of the watch model returned by the function.

    Screenshot of web browser showing the details of the watch model.

In this exercise, you created an Azure Function App in the cloud, and published your functions to this app from Visual Studio.