Skip to content

Commit 7b6f2dd

Browse files
committed
Final working draft
1 parent 54b61f1 commit 7b6f2dd

File tree

4 files changed

+45
-42
lines changed

4 files changed

+45
-42
lines changed

.openpublishing.publish.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
},
7171
{
7272
"path_to_root": "azure_cli_scripts",
73-
"url": "https://github.com/Azure-Samples/azure-cli-samples",
73+
"url": "https://github.com/ggailey777/azure-cli-samples",
7474
"branch": "master",
7575
"branch_mapping": {}
7676
},

articles/azure-functions/create-first-function-cli-csharp.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,11 @@ To learn more, see [Azure Functions HTTP triggers and bindings](./functions-bind
137137
138138
[!INCLUDE [functions-create-azure-resources-cli](../../includes/functions-create-azure-resources-flex-cli.md)]
139139
140-
4. Create the function app in Azure:
140+
7. Create the function app in Azure:
141141
<!---Replace tabs when PowerShell cmdlets support Flex Consumption plans.
142142
### [Azure CLI](#tab/azure-cli)
143143
-->
144-
```azurecli
145-
userId=$(az identity show --name func-host-storage-user --resource-group AzureFunctionsQuickstart-rg --query 'id' -o tsv)
146-
az functionapp create --resource-group AzureFunctionsQuickstart-rg --flexconsumption-location <REGION> --runtime dotnet-isolated --runtime-version 8.0 --assign-identity $userId --deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value $userId --name <APP_NAME> --storage-account <STORAGE_NAME>
147-
```
144+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="37-39":::
148145
149146
The [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command creates the function app in Azure.
150147
<!---
@@ -158,28 +155,24 @@ To learn more, see [Azure Functions HTTP triggers and bindings](./functions-bind
158155
159156
---
160157
-->
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.
158+
In this example, replace these placholders:
162159
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.
160+
+ `<STORAGE_NAME>`: the name of the account you used in the previous step.
161+
+ `<REGION>`: your region.
162+
+ `<APP_NAME>`: a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
163+
+ `<USER_NAME>`: the name of the user-assigned managed identity.
164+
+ `<LANGUAGE>`: use `dotnet-isolated`.
165+
+ `<LANGUAGE_VERSION>`: use `8.0`.
164166
165-
## Update application settings
167+
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.
166168
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.
169+
8. Add your user-assigned managed identity to the [Monitoring Metrics Publisher](../role-based-access-control/built-in-roles/monitor#monitoring-metrics-publisher) role in your Application Insights instance:
168170
169-
1. Remove the existing `AzureWebJobsStorage` connection string setting:
171+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="42-44":::
170172
171-
```azurecli
172-
az functionapp config appsettings delete --name `<APP_NAME>` --resource-group AzureFunctionsQuickstart-rg --setting-names AzureWebJobsStorage
173-
```
173+
The [az role assignment create](/cli/azure/role/assignment#az-role-assignment-create) command adds your user to the role. The resource ID of your Application Insights instance is obtained by using [az monitor app-insights component show](/cli/azure/monitor/app-insights/component#az-monitor-app-insights-component-show).
174174
175-
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:
178-
179-
```azurecli
180-
clientId=$(az identity show --name func-host-storage-user --resource-group AzureFunctionsQuickstart-rg --query 'clientId' -o tsv)
181-
az functionapp config appsettings set --name `<APP_NAME>` --resource-group AzureFunctionsQuickstart-rg --settings AzureWebJobsStorage__accountName=<STORAGE_NAME> AzureWebJobsStorage__credential=managedidentity AzureWebJobsStorage__clientId=$clientId
182-
```
175+
[!INCLUDE [functions-update-app-settings-flex-cli](../../includes/functions-update-app-settings-flex-cli.md)]
183176
184177
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
185178

includes/functions-create-azure-resources-flex-cli.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
3838
---
3939
-->
4040
41+
1. If you haven't already done so, install the Application Insights extension:
42+
43+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="12":::
44+
4145
1. Create a resource group named `AzureFunctionsQuickstart-rg` in your chosen region:
4246
<!---
4347
### [Azure CLI](#tab/azure-cli)-->
4448
45-
```azurecli
46-
az group create --name AzureFunctionsQuickstart-rg --location <REGION>
47-
```
49+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="15":::
4850
4951
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.
5052
<!---
@@ -63,9 +65,7 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
6365
<!---
6466
### [Azure CLI](#tab/azure-cli)
6567
-->
66-
```azurecli
67-
az storage account create --resource-group AzureFunctionsQuickstart-rg --sku Standard_LRS --allow-blob-public-access false --allow-shared-key-access false --name <STORAGE_NAME> --location <REGION>
68-
```
68+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="18-19":::
6969
7070
This [az storage account create](/cli/azure/storage/account#az-storage-account-create) command creates a storage account.
7171
<!---
@@ -79,28 +79,17 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
7979
8080
---
8181
-->
82+
8283
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.
8384
8485
1. Create a user-assigned managed identity, then capture and parse the returned JSON properties of the object using `jq`:
8586
86-
```azurecli
87-
# Create a user-assigned managed identity.
88-
output=$(az identity create --name func-host-storage-user --resource-group AzureFunctionsQuickstart-rg --location <REGION> --query "{userId:id, principalId: principalId, clientId: clientId}" -o json)
89-
90-
# Use jq to parse the JSON and assign the properties to variables.
91-
userId=$(echo $output | jq -r '.userId')
92-
principalId=$(echo $output | jq -r '.principalId')
93-
clientId=$(echo $output | jq -r '.clientId')
94-
```
87+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="22-23,26-28":::
9588
9689
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.
9790
9891
1. Grant to the new identity the required access in the default storage account by using the built-in `Storage Blob Data Owner` role:
9992
100-
```azurecli
101-
# Get the storage ID and create a role assignment (Storage Blob Data Owner) for the UAMI in storage.
102-
storageId=$(az storage account show --resource-group AzureFunctionsQuickstart-rg --name <STORAGE_NAME> --query 'id' -o tsv)
103-
az role assignment create --assignee-object-id $principalId --assignee-principal-type ServicePrincipal --role "Storage Blob Data Owner" --scope $storageId
104-
```
93+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="31-33":::
10594
10695
In this example, replace `<STORAGE_NAME>` and `<REGION>` with your default storage account name and region, respectively.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
author: ggailey777
3+
ms.service: azure-functions
4+
ms.topic: include
5+
ms.date: 05/15/2025
6+
ms.author: glenga
7+
---
8+
9+
## Update application settings
10+
11+
To enable the Functions host to connect to the default storage account using shared secrets, you must replace the `AzureWebJobsStorage` connection string setting with a complex setting, prefixed with `AzureWebJobsStorage`, that uses the user-assigned managed identity to connect to the storage account.
12+
13+
1. Remove the existing `AzureWebJobsStorage` connection string setting:
14+
15+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="52" :::
16+
17+
The [az functionapp config appsettings delete](/cli/azure/functionapp/config/appsettings#az-functionapp-config-appsettings-delete) command removes this setting from your app.
18+
19+
1. Add equivalent settings, with an `AzureWebJobsStorage__` prefix, that define a user-assigned managed identity connection to the default storage account:
20+
21+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="47-51" :::

0 commit comments

Comments
 (0)