You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Quickstart: Add feature flags to an Azure Functions app
14
14
15
-
In this quickstart, you create an Azure Functions app and use feature flags in it. You use the feature management from Azure App Configuration to centrally store all your feature flags and control their states.
15
+
In this quickstart, you create an Azure Functions C# code project and use feature flags in it. You use the feature management from Azure App Configuration to centrally store all your feature flags and control their states.
16
16
17
17
The .NET Feature Management libraries extend the framework with feature flag support. These libraries are built on top of the .NET configuration system. They integrate with App Configuration through its .NET configuration provider.
18
18
19
+
>[!NOTE]
20
+
>This article currently only supports [C# in-process function apps](../azure-functions/functions-dotnet-class-library.md) that run on .NET 6.
21
+
19
22
## Prerequisites
20
23
21
24
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/).
22
25
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
23
26
-[Visual Studio 2019](https://visualstudio.microsoft.com/vs) with the **Azure development** workload.
@@ -30,9 +32,32 @@ Add a feature flag called *Beta* to the App Configuration store and leave **Labe
30
32
> [!div class="mx-imgBorder"]
31
33
> 
32
34
33
-
## Create a Functions app
35
+
## Create a Functions project
36
+
37
+
The Azure Functions project template in Visual Studio creates a C# class library project that you can publish to a function app in Azure. You can use a function app to group functions as a logical unit for easier management, deployment, scaling, and sharing of resources.
38
+
39
+
1. From the Visual Studio menu, select **File** > **New** > **Project**.
40
+
41
+
1. In **Create a new project**, enter *functions* in the search box, choose the **Azure Functions** template, and then select **Next**.
42
+
43
+
1. In **Configure your new project**, enter a **Project name** for your project, and then select **Create**. The function app name must be valid as a C# namespace, so don't use underscores, hyphens, or any other nonalphanumeric characters.
44
+
45
+
1. For the **Create a new Azure Functions application** settings, use the values in the following table:
|**.NET version**|**.NET 6**| This value creates a function project that runs in-process with version 4.x of the Azure Functions runtime. For more information, see [Azure Functions runtime versions overview](../azure-functions/functions-versions.md). |
50
+
|**Function template**|**HTTP trigger**| This value creates a function triggered by an HTTP request. |
51
+
|**Storage account (AzureWebJobsStorage)**|**Storage emulator**| Because a function app in Azure requires a storage account, one is assigned or created when you publish your project to Azure. An HTTP trigger doesn't use an Azure Storage account connection string; all other trigger types require a valid Azure Storage account connection string. |
52
+
|**Authorization level**|**Anonymous**| The created function can be triggered by any client without providing a key. This authorization setting makes it easy to test your new function. For more information about keys and authorization, see [Authorization keys](../azure-functions/functions-bindings-http-webhook-trigger.md#authorization-keys) and [HTTP and webhook bindings](../azure-functions/functions-bindings-http-webhook.md). |
53
+
54
+

55
+
56
+
---
57
+
58
+
Make sure you set the **Authorization level** to **Anonymous**. If you choose the default level of **Function**, you're required to present the [function key](../azure-functions/functions-bindings-http-webhook-trigger.md#authorization-keys) in requests to access your function endpoint.
34
59
35
-
[!INCLUDE [Create a project using the Azure Functions template](../../includes/functions-vstools-create.md)]
60
+
1. Select **Create** to create the function project and HTTP trigger function.
@@ -34,7 +34,7 @@ Before you begin, you must have the following requirements in place:
34
34
35
35
+ The Azure [Az PowerShell module](/powershell/azure/install-azure-powershell) version 5.9.0 or later.
36
36
37
-
+[Python versions that are supported by Azure Functions](supported-languages.md#languages-by-runtime-version).
37
+
+[A Python version supported by Azure Functions](supported-languages.md#languages-by-runtime-version).
38
38
::: zone pivot="python-mode-decorators"
39
39
+ The [Azurite storage emulator](../storage/common/storage-use-azurite.md?tabs=npm#install-azurite). While you can also use an actual Azure Storage account, the article assumes you're using this emulator.
40
40
::: zone-end
@@ -43,7 +43,7 @@ Before you begin, you must have the following requirements in place:
43
43
44
44
## <aname="create-venv"></a>Create and activate a virtual environment
45
45
46
-
In a suitable folder, run the following commands to create and activate a virtual environment named `.venv`. Make sure that you're using a [version of Python that is supported by Azure Functions](supported-languages.md?pivots=programming-language-python#languages-by-runtime-version).
46
+
In a suitable folder, run the following commands to create and activate a virtual environment named `.venv`. Make sure that you're using a [version of Python supported by Azure Functions](supported-languages.md?pivots=programming-language-python#languages-by-runtime-version).
47
47
48
48
### [bash](#tab/bash)
49
49
@@ -148,16 +148,16 @@ In this section, you create a function project and add an HTTP triggered functio
148
148
```
149
149
150
150
If prompted, choose the **ANONYMOUS** option. [`func new`](functions-core-tools-reference.md#func-new) adds an HTTP trigger endpoint named `HttpExample` to the `function_app.py` file, which is accessible without authentication.
151
-
152
-
1. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This is required for Functions to interpret your project correctly as the Python v2 model. You'll add this same setting to your application settings after you publish your project to Azure.
151
+
<!--- Remove these last steps after the next Core Tools version is released (4.28.0)--->
152
+
1. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This setting is required for Functions to interpret your project correctly as the Python v2 model when running locally.
153
153
154
154
1. In the local.settings.json file, update the `AzureWebJobsStorage` setting as in the following example:
This tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you'll need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
160
+
This setting tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
161
161
162
162
1. Run this command to make sure that the Azure Functions library is installed in the environment.
163
163
@@ -208,7 +208,7 @@ Before you can deploy your function code to Azure, you need to create three reso
208
208
209
209
Use the following commands to create these items. Both Azure CLI and PowerShell are supported.
210
210
211
-
1. If you haven't done so already, sign in to Azure.
211
+
1. If needed, sign in to Azure.
212
212
213
213
# [Azure CLI](#tab/azure-cli)
214
214
```azurecli
@@ -282,51 +282,27 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
282
282
# [Azure CLI](#tab/azure-cli)
283
283
284
284
```azurecli
285
-
az functionapp create --resource-group AzureFunctionsQuickstart-rg --consumption-plan-location westeurope --runtime python --runtime-version 3.9 --functions-version 4 --name <APP_NAME> --os-type linux --storage-account <STORAGE_NAME>
285
+
az functionapp create --resource-group AzureFunctionsQuickstart-rg --consumption-plan-location westeurope --runtime python --runtime-version <PYTHON_VERSION> --functions-version 4 --name <APP_NAME> --os-type linux --storage-account <STORAGE_NAME>
286
286
```
287
287
288
-
The [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command creates the function app in Azure. If you're using Python 3.9, 3.8, or 3.7, change `--runtime-version` to `3.9`, `3.8`, or `3.7`, respectively. You must supply `--os-type linux` because Python functions can't run on Windows, which is the default.
288
+
The [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command creates the function app in Azure. You must supply `--os-type linux` because Python functions only run on Linux.
The [New-AzFunctionApp](/powershell/module/az.functions/new-azfunctionapp) cmdlet creates the function app in Azure. If you're using Python 3.9, 3.8, or 3.7, change `-RuntimeVersion` to `3.9`, `3.8`, or `3.7`, respectively.
296
+
The [New-AzFunctionApp](/powershell/module/az.functions/new-azfunctionapp) cmdlet creates the function app in Azure.
297
297
298
298
---
299
299
300
-
In the previous example, replace `<APP_NAME>` with a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
300
+
In the previous example, replace `<APP_NAME>` with a globally unique name appropriate to you. The `<APP_NAME>` is also the default subdomain for the function app. Make sure that the value you set for `<PYTHON_VERSION>` is a [version supported by Functions](supported-languages.md#languages-by-runtime-version) and is the same version you used during local development.
301
301
302
302
This command creates a function app running in your specified language runtime under the [Azure Functions Consumption Plan](consumption-plan.md), which is free for the amount of usage you incur here. The command also creates an associated Azure Application Insights instance in the same resource group, with which you can monitor your function app and view logs. For more information, see [Monitor Azure Functions](functions-monitoring.md). The instance incurs no costs until you activate it.
To use the Python v2 model in your function app, you need to add a new application setting in Azure named `AzureWebJobsFeatureFlags` with a value of `EnableWorkerIndexing`. This setting is already in your local.settings.json file.
310
-
311
-
Run the following command to add this setting to your new function app in Azure.
312
-
313
-
# [Azure CLI](#tab/azure-cli)
314
-
315
-
```azurecli
316
-
az functionapp config appsettings set --name <FUNCTION_APP_NAME> --resource-group <RESOURCE_GROUP_NAME> --settings AzureWebJobsFeatureFlags=EnableWorkerIndexing
In the previous example, replace `<FUNCTION_APP_NAME>` and `<RESOURCE_GROUP_NAME>` with the name of your function app and resource group, respectively. This setting is already in your local.settings.json file.
328
-
::: zone-end
329
-
330
306
## Verify in Azure
331
307
332
308
Run the following command to view near real-time streaming logs in Application Insights in the Azure portal.
Copy file name to clipboardExpand all lines: articles/azure-functions/create-first-function-vs-code-python.md
+8-22Lines changed: 8 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ Completing this quickstart incurs a small cost of a few USD cents or less in you
28
28
29
29
There's also a [CLI-based version](create-first-function-cli-python.md) of this article.
30
30
31
-
This video shows you how to create a Python function in Azure using VS Code.
31
+
This video shows you how to create a Python function in Azure using Visual Studio Code.
32
32
> [!VIDEO a1e10f96-2940-489c-bc53-da2b915c8fc2]
33
33
34
34
The steps in the video are also described in the following sections.
@@ -39,7 +39,7 @@ Before you begin, make sure that you have the following requirements in place:
39
39
40
40
+ An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
41
41
42
-
+ Python versions that are[supported by Azure Functions](supported-languages.md#languages-by-runtime-version). For more information, see [How to install Python](https://wiki.python.org/moin/BeginnersGuide/Download).
42
+
+A Python version that is[supported by Azure Functions](supported-languages.md#languages-by-runtime-version). For more information, see [How to install Python](https://wiki.python.org/moin/BeginnersGuide/Download).
43
43
44
44
+[Visual Studio Code](https://code.visualstudio.com/) on one of the [supported platforms](https://code.visualstudio.com/docs/supporting/requirements#_platforms).
45
45
@@ -58,7 +58,7 @@ Before you begin, make sure that you have the following requirements in place:
58
58
59
59
## <aname="create-an-azure-functions-project"></a>Create your local project
60
60
61
-
In this section, you use Visual Studio Code to create a local Azure Functions project in Python. Later in this article, you'll publish your function code to Azure.
61
+
In this section, you use Visual Studio Code to create a local Azure Functions project in Python. Later in this article, you publish your function code to Azure.
62
62
63
63
1. Choose the Azure icon in the Activity bar. Then in the **Workspace (local)** area, select the **+** button, choose **Create Function** in the dropdown. When prompted, choose **Create new project**.
64
64
@@ -90,16 +90,16 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
90
90
|**Authorization level**| Choose `ANONYMOUS`, which lets anyone call your function endpoint. For more information about the authorization level, see [Authorization keys](functions-bindings-http-webhook-trigger.md#authorization-keys).|
91
91
92
92
4. Visual Studio Code uses the provided information and generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. The generated `function_app.py` project file contains your functions.
93
-
94
-
5. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This is required for Functions to interpret your project correctly as the Python v2 model. You'll add this same setting to your application settings after you publish your project to Azure.
93
+
<!--- Remove these last steps after the next Core Tools version is released (4.28.0)--->
94
+
5. Open the local.settings.json project file and verify that the `AzureWebJobsFeatureFlags` setting has a value of `EnableWorkerIndexing`. This is required for Functions to interpret your project correctly as the Python v2 model when running locally.
95
95
96
96
6. In the local.settings.json file, update the `AzureWebJobsStorage` setting as in the following example:
This tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you'll need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
102
+
This tells the local Functions host to use the storage emulator for the storage connection currently required by the Python v2 model. When you publish your project to Azure, you need to instead use the default storage account. If you're instead using an Azure Storage account, set your storage account connection string here.
103
103
104
104
## Start the emulator
105
105
@@ -110,7 +110,7 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
After you've verified that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.
113
+
After you verify that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.
To use the Python v2 model in your function app, you need to add a new application setting in Azure named `AzureWebJobsFeatureFlags` with a value of `EnableWorkerIndexing`. This setting is already in your local.settings.json file.
160
-
161
-
1. In Visual Studio Code, press <kbd>F1</kbd> to open the command palette. In the command palette, search for and select `Azure Functions: Add New Setting...`.
162
-
163
-
1. Choose your new function app, type `AzureWebJobsFeatureFlags` for the new app setting name, and press <kbd>Enter</kbd>.
164
-
165
-
1. For the value, type `EnableWorkerIndexing` and press <kbd>Enter</kbd>.
166
-
167
-
The setting added to your new function app, which enables it to run the v2 model in Azure.
You have used [Visual Studio Code](functions-develop-vs-code.md?tabs=python) to create a function app with a simple HTTP-triggered function. In the next articles, you expand that function by connecting to Azure Cosmos DB and Azure Storage. To learn more about connecting to other Azure services, see [Add bindings to an existing function in Azure Functions](add-bindings-existing-function.md?tabs=python).
162
+
You created and deployed a function app with a simple HTTP-triggered function. In the next articles, you expand that function by connecting to a storage service in Azure. To learn more about connecting to other Azure services, see [Add bindings to an existing function in Azure Functions](add-bindings-existing-function.md?tabs=python).
177
163
178
164
> [!div class="nextstepaction"]
179
165
> [Connect to Azure Cosmos DB](functions-add-output-binding-cosmos-db-vs-code.md?pivots=programming-language-python)
0 commit comments