Skip to content

Latest commit

 

History

History
181 lines (118 loc) · 8.16 KB

create-first-function-arc-cli.md

File metadata and controls

181 lines (118 loc) · 8.16 KB
title description ms.topic ms.date ms.custom ms.devlang
Quickstart: Create a function app on Azure Arc
Get started with Azure Functions on Azure Arc by deploying your first function app.
quickstart
05/10/2021
mode-other, devx-track-azurecli
azurecli

Create your first function on Azure Arc (preview)

In this quickstart, you create an Azure Functions project and deploy it to a function app running on an Azure Arc-enabled Kubernetes cluster. To learn more, see App Service, Functions, and Logic Apps on Azure Arc. This scenario only supports function apps running on Linux.

Note

Support for running functions on an Azure Arc-enabled Kubernetes cluster is currently in preview.

Publishing PowerShell function projects to Azure Arc-enabled Kubernetes clusters isn't currently supported. If you need to deploy PowerShell functions to Azure Arc-enabled Kubernetes clusters, create your function app in a container.

Prerequisites

On your local computer:


[!INCLUDE functions-arc-create-environment]

[!INCLUDE app-service-arc-cli-install-extensions]

Create the local function project

In Azure Functions, a function project is the unit of deployment and execution for one or more individual functions that each responds to a specific trigger. All functions in a project share the same local and hosting configurations. In this section, you create a function project that contains a single function.

  1. Run the func init command, as follows, to create a functions project in a folder named LocalFunctionProj with the specified runtime:

    func init LocalFunctionProj --dotnet
    func init LocalFunctionProj --javascript

    Python requires a virtual environment, the commands for which differ between bash and a Windows command line.

    • bash:

      python -m venv .venv
      source .venv/bin/activate
    • command line:

      py -m venv .venv
      .venv\scripts\activate

    Now, you create the project inside the virtual environment.

    func init LocalFunctionProj --python

  2. Navigate into the project folder:

    cd LocalFunctionProj

    This folder contains various files for the project, including configurations files named local.settings.json and host.json. By default, the local.settings.json file is excluded from source control in the .gitignore file. This exclusion is because the file can contain secrets that are downloaded from Azure.

  3. Add a function to your project by using the following command, where the --name argument is the unique name of your function (HttpExample) and the --template argument specifies the function's trigger (HTTP).

    func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"

[!INCLUDE functions-run-function-test-local-cli]

[!INCLUDE functions-arc-get-custom-location]

Create Azure resources

Before you can deploy your function code to your new App Service Kubernetes environment, you need to create two more resources:

  • A Storage account, which is currently required by tooling and isn't part of the environment.
  • A function app, which provides the context for executing your function code. The function app runs in the App Service Kubernetes environment and maps to your local function project. A function app lets you group functions as a logical unit for easier management, deployment, and sharing of resources.

Note

Function apps run in an App Service Kubernetes environment on a Dedicated (App Service) plan. When you create your function app without an existing plan, the correct plan is created for you.

Create Storage account

Use the az storage account create command to create a general-purpose storage account in your resource group and region:

az storage account create --name <STORAGE_NAME> --location westeurope --resource-group myResourceGroup --sku Standard_LRS

Note

A storage account is currently required by Azure Functions tooling.

In the previous example, replace <STORAGE_NAME> with a name that is appropriate to you and unique in Azure Storage. Names must contain three to 24 characters numbers and lowercase letters only. Standard_LRS specifies a general-purpose account, which is supported by Functions. The --location value is a standard Azure region.

Create the function app

Run the az functionapp create command to create a new function app in the environment.

az functionapp create --resource-group MyResourceGroup --name <APP_NAME> --custom-location <CUSTOM_LOCATION_ID> --storage-account <STORAGE_NAME> --functions-version 3 --runtime dotnet 
az functionapp create --resource-group MyResourceGroup --name <APP_NAME> --custom-location <CUSTOM_LOCATION_ID> --storage-account <STORAGE_NAME> --functions-version 3 --runtime node --runtime-version 12
az functionapp create --resource-group MyResourceGroup --name <APP_NAME> --custom-location <CUSTOM_LOCATION_ID> --storage-account <STORAGE_NAME> --functions-version 3 --runtime python --runtime-version 3.8

In this example, replace <CUSTOM_LOCATION_ID> with the ID of the custom location you determined for the App Service Kubernetes environment. Also, replace <STORAGE_NAME> with the name of the account you used in the previous step, and replace <APP_NAME> with a globally unique name appropriate to you.

[!INCLUDE functions-publish-project-cli]

Because it can take some time for a full deployment to complete on an Azure Arc-enabled Kubernetes cluster, you may want to re-run the following command to verify your published functions:

func azure functionapp list-functions

[!INCLUDE functions-run-remote-azure-cli]

Next steps

Now that you have your function app running in a container an Azure Arc-enabled App Service Kubernetes environment, you can connect it to Azure Storage by adding a Queue Storage output binding.

[!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