Skip to content

Files

Latest commit

63a8f4b · Nov 18, 2021

History

History
190 lines (117 loc) · 8.39 KB

functions-create-first-function-resource-manager.md

File metadata and controls

190 lines (117 loc) · 8.39 KB
title description ms.date ms.topic ms.service ms.custom
Create your first function using Azure Resource Manager templates
Create and deploy to Azure a simple HTTP triggered serverless function by using an Azure Resource Manager template (ARM template).
3/5/2020
quickstart
azure-functions
subject-armqs, devx-track-azurepowershell, mode-arm

Quickstart: Create and deploy Azure Functions resources from an ARM template

In this article, you use an Azure Resource Manager template (ARM template) to create a function that responds to HTTP requests.

Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.

[!INCLUDE About Azure Resource Manager]

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Deploy to Azure

Prerequisites

Azure account

Before you begin, you must have an Azure account with an active subscription. Create an account for free.

Create a local functions project

This article requires a local functions code project to run on the Azure resources that you create. If you don't first create a project to publish, you won't be able to complete the deployment section of this article.

Choose one of the following tabs, follow the link, and complete the section to create a function app in the language of your choice:

Create your local functions project in your chosen language in Visual Studio Code:

Create your local functions project in Visual Studio

Create your local functions project in your chosen language from the command line:


After you've created your project locally, you create the resources required to run your new function in Azure.

Review the template

The template used in this quickstart is from Azure Quickstart Templates.

:::code language="json" source="~/quickstart-templates/quickstarts/microsoft.web/function-app-create-dynamic/azuredeploy.json":::

The following four Azure resources are created by this template:

Deploy the template

read -p "Enter a resource group name that is used for generating resource names:" resourceGroupName &&
read -p "Enter the location (like 'eastus' or 'northeurope'):" location &&
templateUri="https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/function-app-create-dynamic/azuredeploy.json" &&
az group create --name $resourceGroupName --location "$location" &&
az deployment group create --resource-group $resourceGroupName --template-uri  $templateUri &&
echo "Press [ENTER] to continue ..." &&
read
$resourceGroupName = Read-Host -Prompt "Enter a resource group name that is used for generating resource names"
$location = Read-Host -Prompt "Enter the location (like 'eastus' or 'northeurope')"
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/function-app-create-dynamic/azuredeploy.json"

New-AzResourceGroup -Name $resourceGroupName -Location "$location"
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri

Read-Host -Prompt "Press [ENTER] to continue ..."

Validate the deployment

Next you validate the function app hosting resources you created by publishing your project to Azure and calling the HTTP endpoint of the function.

Publish the function project to Azure

Use the following steps to publish your project to the new Azure resources:

[!INCLUDE functions-republish-vscode]

In the output, copy the URL of the HTTP trigger. You use this to test your function running in Azure.

  1. In Solution Explorer, right-click the project and select Publish.

  2. In Pick a publish target, choose Azure Functions Consumption plan with Select existing and select Create profile.

    :::image type="content" source="media/functions-create-first-function-arm/choose-publish-target-visual-studio.png" alt-text="Choose an existing publish target":::

  3. Choose your Subscription, expand the resource group, select your function app, and select OK.

  4. After the publish completes, copy the Site URL.

    :::image type="content" source="media/functions-create-first-function-arm/publish-summary-site-url.png" alt-text="Copy the site URL from the publish summary":::

  5. Append the path /api/<FUNCTION_NAME>?name=Functions, where <FUNCTION_NAME> is the name of your function. The URL that calls your HTTP trigger function is in the following format:

    http://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>?name=Functions

You use this URL to test your HTTP trigger function running in Azure.

To publish your local code to a function app in Azure, use the publish command:

func azure functionapp publish <FUNCTION_APP_NAME>

In this example, replace <FUNCTION_APP_NAME> with the name of your function app. You may need to sign in again by using az login.

In the output, copy the URL of the HTTP trigger. You use this to test your function running in Azure.


Invoke the function on Azure

Paste the URL you copied for the HTTP request into your browser's address bar, make sure that the name query string as ?name=Functions has been appended to the end of this URL, and then execute the request.

You should see a response like:

Hello Functions!

Clean up resources

If you continue to the next step and add an Azure Storage queue output binding, keep all your resources in place as you'll build on what you've already done.

Otherwise, use the following command to delete the resource group and all its contained resources to avoid incurring further costs.

az group delete --name <RESOURCE_GROUP_NAME>

Replace <RESOURCE_GROUP_NAME> with the name of your resource group.

Next steps

Now that you've publish your first function, learn more by adding an output binding to your function.

[!div class="nextstepaction"] Connect to an Azure Storage queue

[!div class="nextstepaction"] Connect to an Azure Storage queue

[!div class="nextstepaction"] Connect to an Azure Storage queue