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
Copy file name to clipboardExpand all lines: articles/azure-functions/create-first-function-cli-csharp.md
+34-10Lines changed: 34 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,10 +27,12 @@ Before you begin, you must have the following:
27
27
28
28
+ One of the following tools for creating Azure resources:
29
29
30
-
+[Azure CLI](/cli/azure/install-azure-cli)[version 2.4](/cli/azure/release-notes-azure-cli#april-21-2020) or later.
30
+
+[Azure CLI](/cli/azure/install-azure-cli)[version 2.60](/cli/azure/release-notes-azure-cli#november-05-2024) or later.
31
31
32
32
+ The Azure [Az PowerShell module](/powershell/azure/install-azure-powershell) version 5.9.0 or later.
33
33
34
+
+ The [`jq` command line JSON processor](https://jqlang.org/download/), used to parse JSON output, and is also available in Azure Cloud Shell.
35
+
34
36
You also need 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).
@@ -154,10 +157,31 @@ To learn more, see [Azure Functions HTTP triggers and bindings](./functions-bind
154
157
The [New-AzFunctionApp](/powershell/module/az.functions/new-azfunctionapp) cmdlet creates the function app in Azure.
155
158
156
159
---
160
+
-->
161
+
In this example, replace `<STORAGE_NAME>` with the name of the account you used in the previous step, replace `<REGION>` with your region, and replace `<APP_NAME>` with a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
162
+
163
+
This command creates a function app running in your specified language runtime on Linux in the [Flex Consumption Plan](flex-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.
164
+
165
+
## Update application settings
166
+
167
+
To enable the Functions host to connect to the default storage account using shared secrets, you must replace the `AzureWebJobsStorage` connection string setting with an equivalent setting that uses the user-assigned managed identity to connect to the storage account.
157
168
158
-
In the previous example, 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. The `<APP_NAME>` is also the default DNS domain for the function app.
169
+
1. Remove the existing `AzureWebJobsStorage` connection string setting:
159
170
160
-
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.
The [az functionapp config appsettings delete](/cli/azure/functionapp/config/appsettings#az-functionapp-config-appsettings-delete) command removes this setting from your app.
176
+
177
+
1. Add equivalent settings, with an `AzureWebJobsStorage__` prefix, that define a user-assigned managed identity connection to the default storage account:
az functionapp config appsettings set --name `<APP_NAME>` --resource-group AzureFunctionsQuickstart-rg --settings AzureWebJobsStorage__accountName=<STORAGE_NAME> AzureWebJobsStorage__credential=managedidentity AzureWebJobsStorage__clientId=$clientId
182
+
```
183
+
184
+
At this point, the Functions host is able to connect to the storage account securely using managed identities. You can now deploy your project code to the Azure resources
## Create supporting Azure resources for your function
10
+
11
+
Before you can deploy your function code to Azure, you need to create these resources:
12
+
13
+
- A [resource group](../articles/azure-resource-manager/management/overview.md), which is a logical container for related resources.
14
+
- A default [Storage account](../articles/storage/common/storage-account-create.md), which is used by the Functions host to maintain state and other information about your functions.
15
+
- A [user-assigned managed identity](/azure/active-directory/managed-identities-azure-resources/overview), which the Functions host uses to connect to the default storage account.
16
+
- A function app, which provides the environment for executing your function code. A function app maps to your local function project and lets you group functions as a logical unit for easier management, deployment, and sharing of resources.
17
+
18
+
Use the following commands to create these items. Both Azure CLI and PowerShell are supported.
19
+
20
+
1. If you haven't done so already, sign in to Azure:
21
+
22
+
<!---Replace the PowerShell examples after we get the Flex support in the Functions cmdlets.
23
+
### [Azure CLI](#tab/azure-cli)-->
24
+
25
+
```azurecli
26
+
az login
27
+
```
28
+
29
+
The [az login](/cli/azure/reference-index#az-login) command signs you into your Azure account.
30
+
<!---
31
+
### [Azure PowerShell](#tab/azure-powershell)
32
+
```azurepowershell
33
+
Connect-AzAccount
34
+
```
35
+
36
+
The [Connect-AzAccount](/powershell/module/az.accounts/connect-azaccount) cmdlet signs you into your Azure account.
37
+
38
+
---
39
+
-->
40
+
41
+
1. Create a resource group named `AzureFunctionsQuickstart-rg` in your chosen region:
42
+
<!---
43
+
### [Azure CLI](#tab/azure-cli)-->
44
+
45
+
```azurecli
46
+
az group create --name AzureFunctionsQuickstart-rg --location <REGION>
47
+
```
48
+
49
+
The [az group create](/cli/azure/group#az-group-create) command creates a resource group. In the above command, replace `<REGION>` with a region near you that supports the Flex Consumption plan. Use an available region code returned from the [az functionapp list-flexconsumption-locations](/cli/azure/functionapp#az-functionapp-list-flexconsumption-locations) command.
The [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup) command creates a resource group. You generally create your resource group and resources in a region near you, using an available region returned from the [Get-AzLocation](/powershell/module/az.resources/get-azlocation) cmdlet.
58
+
59
+
---
60
+
-->
61
+
62
+
1. Create a general-purpose storage account in your resource group and region:
The [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount) cmdlet creates the storage account.
79
+
80
+
---
81
+
-->
82
+
In this 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](../articles/azure-functions/storage-considerations.md#storage-account-requirements). This new account can only be accessed by using Micrososft Entra-authenticated identities that have been granted permissions to specific resources.
83
+
84
+
1. Create a user-assigned managed identity, then capture and parse the returned JSON properties of the object using `jq`:
If you don't have the `jq` utility in your local Bash shell, it's available in Azure Cloud Shell. The [az identity create](/cli/azure/identity#az-identity-create) command creates a new identity in the resource group named `func-host-storage-user`. The returned `principalId` is used to assign permissions to this new identity in the default storage account by using the [`az role assignment create`](/cli/azure/role/assignment#az-role-assignment-create) command. The [`az storage account show`](/cli/azure/storage/account#az-storage-account-show) command is used to obtain the storage account ID.
97
+
98
+
1. Grant to the new identity the required access in the default storage account by using the built-in `Storage Blob Data Owner` role:
99
+
100
+
```azurecli
101
+
# Get the storage ID and create a role assignment (Storage Blob Data Owner) for the UAMI in storage.
az role assignment create --assignee-object-id $principalId --assignee-principal-type ServicePrincipal --role "Storage Blob Data Owner" --scope $storageId
104
+
```
105
+
106
+
In this example, replace `<STORAGE_NAME>` and `<REGION>` with your default storage account name and region, respectively.
0 commit comments