Skip to content

Commit c0026ec

Browse files
committed
Fix pivot and code issues
1 parent 82d18e5 commit c0026ec

File tree

2 files changed

+58
-37
lines changed

2 files changed

+58
-37
lines changed

articles/azure-functions/how-to-create-function-azure-cli.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,40 @@ Before you begin, you must have the following:
2828
## Create a local function project and function
2929

3030
In Azure Functions, a function project is a container 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.
31-
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python"
32-
1. In a terminal or command prompt, run this [`func init`](./functions-core-tools-reference.md#func-init) command to create a function app project in the current folder:
33-
::: zone-end
3431
::: zone pivot="programming-language-csharp"
32+
1. In a terminal or command prompt, run this [`func init`](./functions-core-tools-reference.md#func-init) command to create a function app project in the current folder:
3533

3634
```console
3735
func init --worker-runtime dotnet-isolated
3836
```
3937

4038
::: zone-end
4139
::: zone pivot="programming-language-javascript"
42-
40+
1. In a terminal or command prompt, run this [`func init`](./functions-core-tools-reference.md#func-init) command to create a function app project in the current folder:
41+
4342
```console
4443
func init --worker-runtime node --language javascript
4544
```
4645

4746
::: zone-end
4847
::: zone pivot="programming-language-powershell"
49-
48+
1. In a terminal or command prompt, run this [`func init`](./functions-core-tools-reference.md#func-init) command to create a function app project in the current folder:
49+
5050
```console
5151
func init --worker-runtime powershell
5252
```
5353

5454
::: zone-end
5555
::: zone pivot="programming-language-python"
56-
56+
1. In a terminal or command prompt, run this [`func init`](./functions-core-tools-reference.md#func-init) command to create a function app project in the current folder:
57+
5758
```console
5859
func init --worker-runtime python
5960
```
6061

6162
::: zone-end
6263
::: zone pivot="programming-language-typescript"
64+
1. In a terminal or command prompt, run this [`func init`](./functions-core-tools-reference.md#func-init) command to create a function app project in the current folder:
6365
6466
```console
6567
func init --worker-runtime node --language typescript
@@ -184,7 +186,7 @@ In Azure Functions, a function project is a container for one or more individual
184186

185187
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.
186188

187-
1. Use this script to get the client ID of the user-assigned managed identity, and with it define a managed identity connections to storage and Application Insights:
189+
1. Use this script to get the client ID of the user-assigned managed identity and uses it to define managed identity connections to both storage and Application Insights:
188190
189191
```azurecli
190192
clientId=$(az identity show --name func-host-storage-user \

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

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Before you can deploy your function code to Azure, you need to create these reso
1515
- 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.
1616
- 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.
1717

18-
Use the following commands to create these items. Both Azure CLI and PowerShell are supported.
18+
Use the Azure CLI commands in these steps to create the required resources.
1919

2020
1. If you haven't done so already, sign in to Azure:
2121

@@ -38,17 +38,21 @@ 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:
41+
1. If you haven't already done so, use this [`az extension add`](/cli/azure/extension#az-extension-add) command to install the Application Insights extension:
4242
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":::
43+
```azurecli
44+
az extension add --name application-insights
45+
```
4446
45-
1. Create a resource group named `AzureFunctionsQuickstart-rg` in your chosen region:
47+
1. Use this [az group create](/cli/azure/group#az-group-create) command to create a resource group named `AzureFunctionsQuickstart-rg` in your chosen region:
4648
<!---
4749
### [Azure CLI](#tab/azure-cli)-->
4850
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":::
51+
```azurecli
52+
az group create --name "AzureFunctionsQuickstart-rg" --location "<REGION>"
53+
```
5054
51-
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.
55+
In this example, replace `<REGION>` with a region near you that supports the Flex Consumption plan. Use the [az functionapp list-flexconsumption-locations](/cli/azure/functionapp#az-functionapp-list-flexconsumption-locations) command to view the list of currently supported regions.
5256
<!---
5357
### [Azure PowerShell](#tab/azure-powershell)
5458
@@ -61,13 +65,16 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
6165
---
6266
-->
6367
64-
1. Create a general-purpose storage account in your resource group and region:
68+
1. Use this [az storage account create](/cli/azure/storage/account#az-storage-account-create) command to create a general-purpose storage account in your resource group and region:
6569
<!---
6670
### [Azure CLI](#tab/azure-cli)
6771
-->
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":::
72+
```azurecli
73+
az storage account create --name <STORAGE_NAME> --location "<REGION>" --resource-group "AzureFunctionsQuickstart-rg" \
74+
--sku "Standard_LRS" --allow-blob-public-access false --allow-shared-key-access false
75+
```
6976
70-
This [az storage account create](/cli/azure/storage/account#az-storage-account-create) command creates a storage account.
77+
7178
<!---
7279
### [Azure PowerShell](#tab/azure-powershell)
7380
@@ -82,55 +89,62 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
8289
8390
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 Microsoft Entra-authenticated identities that have been granted permissions to specific resources.
8491
85-
1. Create a user-assigned managed identity, then capture and parse the returned JSON properties of the object using `jq`:
92+
1. Use this script to create a user-assigned managed identity, parse the returned JSON properties of the object using `jq`, and grant `Storage Blob Data Owner` permissions in the default storage account:
8693
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":::
94+
```azurecli
95+
output=$(az identity create --name "func-host-storage-user" --resource-group "AzureFunctionsQuickstart-rg" --location <REGION> \
96+
--query "{userId:id, principalId: principalId, clientId: clientId}" -o json)
8897
89-
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.
98+
userId=$(echo $output | jq -r '.userId')
99+
principalId=$(echo $output | jq -r '.principalId')
100+
clientId=$(echo $output | jq -r '.clientId')
90101
91-
1. Grant to the new identity the required access in the default storage account by using the built-in `Storage Blob Data Owner` role:
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 \
104+
--role "Storage Blob Data Owner" --scope $storageId
105+
```
92106
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":::
107+
If you don't have the `jq` utility in your local Bash shell, it's available in Azure Cloud Shell. In this example, replace `<STORAGE_NAME>` and `<REGION>` with your default storage account name and region, respectively.
94108
95-
In this example, replace `<STORAGE_NAME>` and `<REGION>` with your default storage account name and region, respectively.
109+
The [az identity create](/cli/azure/identity#az-identity-create) command creates an identity 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.
96110
97-
1. Use the [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command to create the function app in Azure:
111+
1. Use this [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command to create the function app in Azure:
98112
<!---Replace tabs when PowerShell cmdlets support Flex Consumption plans.
99113
### [Azure CLI](#tab/azure-cli)
100114
-->
101115
::: zone pivot="programming-language-csharp"
102116
```azurecli
103117
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
104118
--runtime dotnet-isolated --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
105-
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
119+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value "func-host-storage-user"
106120
```
107121
::: zone-end
108122
::: zone pivot="programming-language-java"
109123
```azurecli
110124
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
111125
--runtime java --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
112-
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
126+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value "func-host-storage-user"
113127
```
114128
::: zone-end
115129
::: zone pivot="programming-language-javascript,programming-language-typescript"
116130
```azurecli
117131
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
118132
--runtime node --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
119-
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
133+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value "func-host-storage-user"
120134
```
121135
::: zone-end
122136
::: zone pivot="programming-language-python"
123137
```azurecli
124138
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
125139
--runtime python --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
126-
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
140+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value "func-host-storage-user"
127141
```
128142
::: zone-end
129143
::: zone pivot="programming-language-powershell"
130144
```azurecli
131145
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
132146
--runtime python --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
133-
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
147+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value "func-host-storage-user"
134148
```
135149
::: zone-end
136150
<!---
@@ -144,18 +158,23 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
144158
145159
---
146160
-->
147-
In this example, replace these placeholders:
161+
In this example, replace these placeholders with the appropriate values:
148162
163+
+ `<APP_NAME>`: a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
149164
+ `<STORAGE_NAME>`: the name of the account you used in the previous step.
150-
+ `<REGION>`: your region.
151-
+ `<APP_NAME>`: a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
152-
+ `<USER_NAME>`: the name of the user-assigned managed identity.
153-
+ `<LANGUAGE_VERSION>`: use the [supported language stack version](../articles/azure-functions/supported-languages.md) you verified locally.
165+
+ `<REGION>`: your current region.
166+
+ `<LANGUAGE_VERSION>`: use the same [supported language stack version](../articles/azure-functions/supported-languages.md) you verified locally.
154167
155-
This command creates a function app running in your specified language runtime on Linux in the [Flex Consumption Plan](../articles/azure-functions/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](../articles/azure-functions/functions-monitoring.md). The instance incurs no costs until you activate it.
168+
This command creates a function app running in your specified language runtime on Linux in the [Flex Consumption Plan](../articles/azure-functions/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 use to monitor your function app executions and view logs. For more information, see [Monitor Azure Functions](../articles/azure-functions/functions-monitoring.md). The instance incurs no costs until you activate it.
156169
157-
1. Add your user-assigned managed identity to the [Monitoring Metrics Publisher](../articles/role-based-access-control/built-in-roles/monitor.md#monitoring-metrics-publisher) role in your Application Insights instance:
170+
1. Use this script to add your user-assigned managed identity to the [Monitoring Metrics Publisher](../articles/role-based-access-control/built-in-roles/monitor.md#monitoring-metrics-publisher) role in your Application Insights instance:
158171
159-
:::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":::
172+
```azurecli
173+
appInsights=$(az monitor app-insights component show --resource-group "AzureFunctionsQuickstart-rg" \
174+
--app <APP_NAME> --query "id" --output tsv)
175+
principalId=$(az identity show --name "func-host-storage-user" --resource-group "AzureFunctionsQuickstart-rg" \
176+
--query principalId -o tsv)
177+
az role assignment create --role "Monitoring Metrics Publisher" --assignee $principalId --scope $appInsights
178+
```
160179
161-
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).
180+
In this example, replace `<APP_NAME>` with the name of your function app. 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 and the principal ID of your user are obtained by using the [az monitor app-insights component show](/cli/azure/monitor/app-insights/component#az-monitor-app-insights-component-show) and [`az identity show`](/cli/azure/identity#az-identity-show) commands, respectively.

0 commit comments

Comments
 (0)