Skip to content

Commit 0229151

Browse files
committed
Rough in multi-lang updates for MI w/ pivots
1 parent 59568eb commit 0229151

File tree

4 files changed

+287
-22
lines changed

4 files changed

+287
-22
lines changed

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,8 @@ By default, the Flex Consumption plan follows a _pay-for-what-you-use_ billing m
2525

2626
+ [Azure Functions Core Tools](functions-run-local.md#install-the-azure-functions-core-tools).
2727

28-
::: zone pivot="programming-language-csharp"
29-
+ [.NET 8.0 SDK](https://dotnet.microsoft.com/download)
30-
31-
+ [Azurite storage emulator](../storage/common/storage-use-azurite.md?tabs=npm#install-azurite)
32-
::: zone-end
33-
::: zone pivot="programming-language-java"
34-
+ [Java 17 Developer Kit](/azure/developer/java/fundamentals/java-support-on-azure)
35-
+ If you use another [supported version of Java](supported-languages.md?pivots=programming-language-java#languages-by-runtime-version), you must update the project's pom.xml file.
36-
+ The `JAVA_HOME` environment variable must be set to the install location of the correct version of the JDK.
37-
+ [Apache Maven 3.8.x](https://maven.apache.org)
38-
::: zone-end
39-
::: zone pivot="programming-language-javascript,programming-language-typescript"
40-
+ [Node.js 20](https://nodejs.org/)
41-
::: zone-end
42-
::: zone pivot="programming-language-powershell"
43-
+ [PowerShell 7.2](/powershell/scripting/install/installing-powershell-core-on-windows)
28+
[!INCLUDE [functions-requirements-azure-cli](../../includes/functions-requirements-azure-cli.md)]
4429

45-
+ [.NET 6.0 SDK](https://dotnet.microsoft.com/download)
46-
::: zone-end
47-
::: zone pivot="programming-language-python"
48-
+ [Python 3.11](https://www.python.org/).
49-
::: zone-end
5030
+ A [secure HTTP test tool](functions-develop-local.md#http-test-tools) for sending requests with JSON payloads to your function endpoints. This article uses `curl`.
5131

5232
## Initialize the project
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
---
2+
title: "Create a function in Azure using the Azure CLI"
3+
description: "Learn how to create an Azure Functions code project from the command line using the Azure CLI, then publish the local project to serverless hosting in Azure Functions."
4+
ms.date: 07/08/2025
5+
ms.topic: quickstart
6+
ms.custom: devx-track-csharp, devx-track-azurecli, devx-track-azurepowershell, mode-other, devx-track-dotnet
7+
zone_pivot_groups: programming-languages-set-functions
8+
---
9+
10+
# Quickstart: Create a function in Azure from the command line
11+
12+
In this article, you use command-line tools locally to create a function that responds to HTTP requests. After verifying your code locally, you deploy it to a serverless hosting plan in Azure Functions.
13+
14+
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
15+
16+
## Configure your local environment
17+
18+
Before you begin, you must have the following:
19+
20+
[!INCLUDE [functions-requirements-azure-cli](../../includes/functions-requirements-azure-cli.md)]
21+
22+
+ The [`jq` command line JSON processor](https://jqlang.org/download/), used to parse JSON output, and is also available in Azure Cloud Shell.
23+
24+
[!INCLUDE [functions-install-core-tools](../../includes/functions-install-core-tools.md)]
25+
26+
## Create a local function project and function
27+
28+
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.
29+
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python"
30+
1. In a terminal or command prompt, run the following command for your chosen language to create a function app project in the current folder:
31+
::: zone-end
32+
::: zone pivot="programming-language-csharp"
33+
34+
```console
35+
func init --worker-runtime dotnet-isolated
36+
```
37+
::: zone-end
38+
::: zone pivot="programming-language-javascript"
39+
```console
40+
func init --worker-runtime node --language javascript
41+
```
42+
::: zone-end
43+
::: zone pivot="programming-language-powershell"
44+
```console
45+
func init --worker-runtime powershell
46+
```
47+
::: zone-end
48+
::: zone pivot="programming-language-python"
49+
```console
50+
func init --worker-runtime python
51+
```
52+
::: zone-end
53+
::: zone pivot="programming-language-typescript"
54+
```console
55+
func init --worker-runtime node --language typescript
56+
```
57+
::: zone-end
58+
::: zone pivot="programming-language-java"
59+
<!--- The Maven archetype requires it's own create flow...-->
60+
1. In an empty folder, run this `mvn` command to generate the code project from an Azure Functions [Maven archetype](https://maven.apache.org/guides/introduction/introduction-to-archetypes.html):
61+
62+
63+
### [Bash](#tab/bash)
64+
65+
```bash
66+
mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=8
67+
```
68+
69+
### [PowerShell](#tab/powershell)
70+
71+
```powershell
72+
mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=8"
73+
```
74+
75+
### [Cmd](#tab/cmd)
76+
77+
```cmd
78+
mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=8"
79+
```
80+
81+
---
82+
83+
> [!IMPORTANT]
84+
> + Use `-DjavaVersion=11` if you want your functions to run on Java 11. To learn more, see [Java versions](functions-reference-java.md#java-versions).
85+
> + The `JAVA_HOME` environment variable must be set to the install location of the correct version of the JDK to complete this article.
86+
87+
2. Maven asks you for values needed to finish generating the project on deployment.
88+
Provide the following values when prompted:
89+
90+
| Prompt | Value | Description |
91+
| ------ | ----- | ----------- |
92+
| **groupId** | `com.fabrikam` | A value that uniquely identifies your project across all projects, following the [package naming rules](https://docs.oracle.com/javase/specs/jls/se6/html/packages.html#7.7) for Java. |
93+
| **artifactId** | `fabrikam-functions` | A value that is the name of the jar, without a version number. |
94+
| **version** | `1.0-SNAPSHOT` | Choose the default value. |
95+
| **package** | `com.fabrikam` | A value that is the Java package for the generated function code. Use the default. |
96+
97+
3. Type `Y` or press Enter to confirm.
98+
99+
Maven creates the project files in a new folder with a name of _artifactId_, which in this example is `fabrikam-functions`.
100+
101+
4. Navigate into the project folder:
102+
103+
```console
104+
cd fabrikam-functions
105+
```
106+
::: zone-end
107+
108+
The project root folder contains various files for the project, including configurations files named [local.settings.json](functions-develop-local.md#local-settings-file) and [host.json](functions-host-json.md). Because *local.settings.json* can contain secrets downloaded from Azure, the file is excluded from source control by default in the *.gitignore* file.
109+
110+
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python"
111+
2. Use this `func new` command to add a function to your project:
112+
113+
```console
114+
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"
115+
```
116+
117+
A new code file is added to your project. In this case, the `--name` argument is the unique name of your function (`HttpExample`) and the `--template` argument specifies an HTTP trigger.
118+
::: zone-end
119+
## Run the function locally
120+
121+
1. Run your function by starting the local Azure Functions runtime host from the root folder:
122+
123+
To test the function locally, start the local Azure Functions runtime host in the root of the project folder.
124+
::: zone pivot="programming-language-csharp"
125+
```console
126+
func start
127+
```
128+
::: zone-end
129+
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
130+
```console
131+
func start
132+
```
133+
::: zone-end
134+
::: zone pivot="programming-language-typescript"
135+
```console
136+
npm install
137+
npm start
138+
```
139+
::: zone-end
140+
::: zone pivot="programming-language-java"
141+
```console
142+
mvn clean package
143+
mvn azure-functions:run
144+
```
145+
::: zone-end
146+
147+
Toward the end of the output, the following lines should appear:
148+
149+
<pre>
150+
...
151+
152+
Now listening on: http://0.0.0.0:7071
153+
Application started. Press Ctrl+C to shut down.
154+
155+
Http Functions:
156+
157+
HttpExample: [GET,POST] http://localhost:7071/api/HttpExample
158+
...
159+
160+
</pre>
161+
162+
>[!NOTE]
163+
> If HttpExample doesn't appear as shown above, you likely started the host from outside the root folder of the project. In that case, use **Ctrl**+**C** to stop the host, navigate to the project's root folder, and run the previous command again.
164+
165+
1. Copy the URL of your `HttpExample` function from this output to a browser and browse to the function URL and you should receive success response with a "hello world" message.
166+
167+
1. When you're done, use **Ctrl**+**C** and choose `y` to stop the functions host.
168+
169+
[!INCLUDE [functions-create-azure-resources-cli](../../includes/functions-create-azure-resources-flex-cli.md)]
170+
171+
## Update application settings
172+
173+
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.
174+
175+
1. Remove the existing `AzureWebJobsStorage` connection string setting:
176+
177+
:::code language="azurecli" source="~/azure_cli_scripts/azure-functions/create-function-app-flex-plan-identities/create-function-app-flex-plan-identities.md" range="52" :::
178+
179+
The [az functionapp config appsettings delete](/cli/azure/functionapp/config/appsettings#az-functionapp-config-appsettings-delete) command removes this setting from your app.
180+
181+
1. Add equivalent settings, with an `AzureWebJobsStorage__` prefix, that define a user-assigned managed identity connection to the default storage account:
182+
183+
:::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" :::
184+
185+
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
186+
187+
[!INCLUDE [functions-publish-project-cli](../../includes/functions-publish-project-cli.md)]
188+
189+
## Invoke the function on Azure
190+
191+
Because your function uses an HTTP trigger and supports GET requests, you invoke it by making an HTTP request to its URL. It's easiest to do this in a browser.
192+
193+
Copy the complete **Invoke URL** shown in the output of the publish command into a browser address bar. When you navigate to this URL, the browser should display similar output as when you ran the function locally.
194+
195+
---
196+
197+
[!INCLUDE [functions-streaming-logs-cli-qs](../../includes/functions-streaming-logs-cli-qs.md)]
198+
199+
[!INCLUDE [functions-cleanup-resources-cli](../../includes/functions-cleanup-resources-cli.md)]
200+
201+
## Next steps
202+
203+
> [!div class="nextstepaction"]
204+
> [Connect to Azure Cosmos DB](functions-add-output-binding-cosmos-db-vs-code.md?pivots=programming-language-csharp&tabs=isolated-process)
205+
> [!div class="nextstepaction"]
206+
> [Connect to Azure Queue Storage](functions-add-output-binding-storage-queue-cli.md?pivots=programming-language-csharp&tabs=isolated-process)

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: ggailey777
33
ms.service: azure-functions
44
ms.topic: include
5-
ms.date: 11/16/2024
5+
ms.date: 07/05/2025
66
ms.author: glenga
77
---
88

@@ -93,3 +93,59 @@ Use the following commands to create these items. Both Azure CLI and PowerShell
9393
:::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":::
9494
9595
In this example, replace `<STORAGE_NAME>` and `<REGION>` with your default storage account name and region, respectively.
96+
97+
1. Use the [az functionapp create](/cli/azure/functionapp#az-functionapp-create) command to create the function app in Azure:
98+
<!---Replace tabs when PowerShell cmdlets support Flex Consumption plans.
99+
### [Azure CLI](#tab/azure-cli)
100+
-->
101+
::: zone pivot="programming-language-csharp"
102+
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
103+
--runtime dotnet-isolated --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
104+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
105+
::: zone-end
106+
::: zone pivot="programming-language-java"
107+
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
108+
--runtime java --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
109+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
110+
::: zone-end
111+
::: zone pivot="programming-language-javascript,programming-language-typescript"
112+
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
113+
--runtime node --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
114+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
115+
::: zone-end
116+
::: zone pivot="programming-language-python"
117+
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
118+
--runtime python --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
119+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
120+
::: zone-end
121+
::: zone pivot="programming-language-powershell"
122+
az functionapp create --resource-group "AzureFunctionsQuickstart-rg" --name <APP_NAME> --flexconsumption-location <REGION> \
123+
--runtime python --runtime-version <LANGUAGE_VERSION> --storage-account <STORAGE_NAME> \
124+
--deployment-storage-auth-type UserAssignedIdentity --deployment-storage-auth-value <USER_NAME>
125+
::: zone-end
126+
<!---
127+
### [Azure PowerShell](#tab/azure-powershell)
128+
129+
```azurepowershell
130+
New-AzFunctionApp -Name <APP_NAME> -ResourceGroupName AzureFunctionsQuickstart-rg -StorageAccount <STORAGE_NAME> -Runtime dotnet-isolated -FunctionsVersion 4 -Location '<REGION>'
131+
```
132+
133+
The [New-AzFunctionApp](/powershell/module/az.functions/new-azfunctionapp) cmdlet creates the function app in Azure.
134+
135+
---
136+
-->
137+
In this example, replace these placholders:
138+
139+
+ `<STORAGE_NAME>`: the name of the account you used in the previous step.
140+
+ `<REGION>`: your region.
141+
+ `<APP_NAME>`: a globally unique name appropriate to you. The `<APP_NAME>` is also the default DNS domain for the function app.
142+
+ `<USER_NAME>`: the name of the user-assigned managed identity.
143+
+ `<LANGUAGE_VERSION>`: use the [supported language stack version](../articles/azure-functions/supported-languages.md) you verified locally.
144+
145+
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.
146+
147+
1. Add your user-assigned managed identity to the [Monitoring Metrics Publisher](../role-based-access-control/built-in-roles/monitor.md#monitoring-metrics-publisher) role in your Application Insights instance:
148+
149+
:::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":::
150+
151+
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).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
::: zone pivot="programming-language-csharp"
3+
+ [.NET 8.0 SDK](https://dotnet.microsoft.com/download)
4+
5+
+ [Azurite storage emulator](../storage/common/storage-use-azurite.md?tabs=npm#install-azurite)
6+
::: zone-end
7+
::: zone pivot="programming-language-java"
8+
+ [Java 17 Developer Kit](/azure/developer/java/fundamentals/java-support-on-azure)
9+
+ If you use another [supported version of Java](supported-languages.md?pivots=programming-language-java#languages-by-runtime-version), you must update the project's pom.xml file.
10+
+ The `JAVA_HOME` environment variable must be set to the install location of the correct version of the JDK.
11+
+ [Apache Maven 3.8.x](https://maven.apache.org)
12+
::: zone-end
13+
::: zone pivot="programming-language-javascript,programming-language-typescript"
14+
+ [Node.js 20](https://nodejs.org/)
15+
::: zone-end
16+
::: zone pivot="programming-language-powershell"
17+
+ [PowerShell 7.2](/powershell/scripting/install/installing-powershell-core-on-windows)
18+
19+
+ [.NET 6.0 SDK](https://dotnet.microsoft.com/download)
20+
::: zone-end
21+
::: zone pivot="programming-language-python"
22+
+ [Python 3.11](https://www.python.org/).
23+
::: zone-end

0 commit comments

Comments
 (0)