| title | Create a function in Azure from the command line |
|---|---|
| description | Learn how to use command line tools, such as Azure Functions Core Tools, to create a function code project, create Azure resources, and publish function code to run in Azure Functions. |
| ms.date | 07/22/2025 |
| ms.topic | quickstart |
| ms.custom | devx-track-csharp, devx-track-azurecli, devx-track-azurepowershell, mode-other, devx-track-dotnet |
| zone_pivot_groups | programming-languages-set-functions-full |
In this article, you use local command-line tools to create a function that responds to HTTP requests. After verifying your code locally, you deploy it to a serverless Flex Consumption hosting plan in Azure Functions.
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
Make sure to select your preferred development language at the top of the article.
- An Azure account with an active subscription. Create an account for free.
[!INCLUDE functions-requirements-azure-cli] ::: zone pivot="programming-language-other"
- Go, latest version recommended. Use the
go versioncommand to check your version.
- Rust toolchain using rustup. Use the
rustc --versioncommand to check your version.
::: zone-end
-
The
jqcommand line JSON processor, used to parse JSON output, and is also available in Azure Cloud Shell.
[!INCLUDE functions-install-core-tools]
[!INCLUDE functions-cli-create-venv]
In Azure Functions, your code project is an app that contains one or more individual functions that each respond to a specific trigger. All functions in a project share the same configurations and are deployed as a unit to Azure. In this section, you create a code project that contains a single function. ::: zone pivot="programming-language-csharp"
-
In a terminal or command prompt, run this
func initcommand to create a function app project in the current folder:func init --worker-runtime dotnet-isolated
::: zone-end
::: zone pivot="programming-language-javascript"
-
In a terminal or command prompt, run this
func initcommand to create a function app project in the current folder:func init --worker-runtime node --language javascript
::: zone-end
::: zone pivot="programming-language-powershell"
-
In a terminal or command prompt, run this
func initcommand to create a function app project in the current folder:func init --worker-runtime powershell
::: zone-end
::: zone pivot="programming-language-python"
-
In a terminal or command prompt, run this
func initcommand to create a function app project in the current folder:func init --worker-runtime python
::: zone-end
::: zone pivot="programming-language-typescript"
-
In a terminal or command prompt, run this
func initcommand to create a function app project in the current folder:func init --worker-runtime node --language typescript
::: zone-end ::: zone pivot="programming-language-other"
-
In a terminal or command prompt, run this
func initcommand to create a function app project in the current folder:func init --worker-runtime custom
::: zone-end ::: zone pivot="programming-language-java"
-
In an empty folder, run this
mvncommand to generate the code project from an Azure Functions Maven archetype:mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=17
mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=17"
mvn archetype:generate "-DarchetypeGroupId=com.microsoft.azure" "-DarchetypeArtifactId=azure-functions-archetype" "-DjavaVersion=17"
[!IMPORTANT]
- Use
-DjavaVersion=11if you want your functions to run on Java 11. To learn more, see Java versions. - Set the
JAVA_HOMEenvironment variable to the install location of the correct version of the JDK to complete this article.
- Use
-
Maven asks you for values needed to finish generating the project on deployment.
Provide the following values when prompted:Prompt Value Description groupId com.fabrikamA value that uniquely identifies your project across all projects, following the package naming rules for Java. artifactId fabrikam-functionsA value that is the name of the jar, without a version number. version 1.0-SNAPSHOTChoose the default value. package com.fabrikamA value that is the Java package for the generated function code. Use the default. -
Type
Yor press Enter to confirm.Maven creates the project files in a new folder with a name of artifactId, which in this example is
fabrikam-functions. -
Navigate into the project folder:
cd fabrikam-functionsYou can review the template-generated code for your new HTTP trigger function in Function.java in the \src\main\java\com\fabrikam project directory. ::: zone-end
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python,programming-language-other" -
Use this
func newcommand to add a function to your project:func new --name HttpExample --template "HTTP trigger" --authlevel "function"A new code file is added to your project. In this case, the
--nameargument is the unique name of your function (HttpExample) and the--templateargument specifies an HTTP trigger. ::: zone-end
The project root folder contains various files for the project, including configurations files named local.settings.json and host.json. Because local.settings.json can contain secrets downloaded from Azure, the file is excluded from source control by default in the .gitignore file.
::: zone pivot="programming-language-other"
[!INCLUDE functions-custom-handler-create-function-code]
::: zone-end
Verify your new function by running the project locally and calling the function endpoint.
-
Use this command to start the local Azure Functions runtime host in the root of the project folder: ::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-powershell,programming-language-python,programming-language-other"
func start::: zone-end
::: zone pivot="programming-language-typescript"npm install npm start
::: zone-end
::: zone pivot="programming-language-java"mvn clean package mvn azure-functions:run
::: zone-end
Toward the end of the output, the following lines appear:
... Now listening on: http://0.0.0.0:7071 Application started. Press Ctrl+C to shut down. Http Functions: HttpExample: [GET,POST] http://localhost:7071/api/HttpExample ... -
Copy the URL of your
HttpExamplefunction from this output to a browser and browse to the function URL. You should receive a success response with a "hello world" message.[!NOTE] Because access key authorization isn't enforced when running locally, the function URL returned doesn't include the access key value and you don't need it to call your function.
-
When you're done, use Ctrl+C and choose
yto stop the functions host.
[!INCLUDE functions-create-azure-resources-cli]
To enable the Functions host to connect to the default storage account by using shared secrets, replace the AzureWebJobsStorage connection string setting with several settings that are prefixed with AzureWebJobsStorage__. These settings define a complex setting that your app uses to connect to storage and Application Insights with a user-assigned managed identity.
-
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:
clientId=$(az identity show --name func-host-storage-user \ --resource-group AzureFunctionsQuickstart-rg --query 'clientId' -o tsv) az functionapp config appsettings set --name <APP_NAME> --resource-group "AzureFunctionsQuickstart-rg" \ --settings AzureWebJobsStorage__accountName=<STORAGE_NAME> \ AzureWebJobsStorage__credential=managedidentity AzureWebJobsStorage__clientId=$clientId \ APPLICATIONINSIGHTS_AUTHENTICATION_STRING="ClientId=$clientId;Authorization=AAD"In this script, replace
<APP_NAME>and<STORAGE_NAME>with the names of your function app and storage account, respectively. -
Run the az functionapp config appsettings delete command to remove the existing
AzureWebJobsStorageconnection string setting, which contains a shared secret key:az functionapp config appsettings delete --name <APP_NAME> --resource-group "AzureFunctionsQuickstart-rg" --setting-names AzureWebJobsStorageIn this example, replace
<APP_NAME>with the names of your function app.
At this point, the Functions host can connect to the storage account securely by using managed identities instead of shared secrets. You can now deploy your project code to the Azure resources.
::: zone pivot="programming-language-csharp,programming-language-javascript,programming-language-typescript,programming-language-powershell,programming-language-python,programming-language-other" [!INCLUDE functions-publish-project-cli] ::: zone-end ::: zone pivot="programming-language-java"
After you successfully create your function app in Azure, update the pom.xml file so that Maven can deploy to your new app. Otherwise, Maven creates a new set of Azure resources during deployment.
-
In Azure Cloud Shell, use this
az functionapp showcommand to get the deployment container URL and ID of the new user-assigned managed identity:az functionapp show --name <APP_NAME> --resource-group AzureFunctionsQuickstart-rg \ --query "{userAssignedIdentityResourceId: properties.functionAppConfig.deployment.storage.authentication.userAssignedIdentityResourceId, \ containerUrl: properties.functionAppConfig.deployment.storage.value}"In this example, replace
<APP_NAME>with the names of your function app. -
In the project root directory, open the pom.xml file in a text editor, locate the
propertieselement, and update these specific property values:Property name Value java.versionUse the same supported language stack version you verified locally, such as 17.azure.functions.maven.plugin.version1.37.1azure.functions.java.library.version3.1.0functionAppNameThe name of your function app in Azure. -
Find the
configurationsection of theazure-functions-maven-pluginand replace it with this XML fragment:<configuration> <appName>${functionAppName}</appName> <resourceGroup>AzureFunctionsQuickstart-rg</resourceGroup> <pricingTier>Flex Consumption</pricingTier> <region>....</region> <runtime> <os>linux</os> <javaVersion>${java.version}</javaVersion> </runtime> <deploymentStorageAccount>...</deploymentStorageAccount> <deploymentStorageResourceGroup>AzureFunctionsQuickstart-rg</deploymentStorageResourceGroup> <deploymentStorageContainer>...</deploymentStorageContainer> <storageAuthenticationMethod>UserAssignedIdentity</storageAuthenticationMethod> <userAssignedIdentityResourceId>...</userAssignedIdentityResourceId> <appSettings> <property> <name>FUNCTIONS_EXTENSION_VERSION</name> <value>~4</value> </property> </appSettings> </configuration>
-
In the new
configurationelement, make these specific replacements of the ellipses (...) values:Configuration Value regionThe region code of your existing function app, such as eastus.deploymentStorageAccountThe name of your storage account. deploymentStorageContainerThe name of the deployment share, which comes after the \in thecontainerUrlvalue you obtained.userAssignedIdentityResourceIdThe fully qualified resource ID of your managed identity, which you obtained. -
Save your changes to the pom.xml file.
You can now use Maven to deploy your code project to your existing app.
-
From the command prompt, run this command:
mvn clean package azure-functions:deploy -
After your deployment succeeds, run this Core Tools command to get the URL endpoint value, including the access key:
func azure functionapp list-functions <APP_NAME> --show-keysIn this example, again replace
<APP_NAME>with the name of your app. -
Copy the returned endpoint URL and key, which you use to invoke the function endpoint.
::: zone-end
Because your function uses an HTTP trigger and supports GET requests, you invoke it by making an HTTP request to its URL using the function-level access key. It's easiest to execute a GET request in a browser.
Paste the URL and access key you copied into a browser address bar.
The endpoint URL should look something like this example:
https://contoso-app.azurewebsites.net/api/httpexample?code=aabbccdd...
In this case, you must also provide an access key in the query string when making a GET request to the endpoint URL. Using an access key is recommended to limit access from random clients. When making a POST request using an HTTP client, you should instead provide the access key in the x-functions-key header.
When you navigate to this URL, the browser should display similar output as when you ran the function locally.
[!INCLUDE functions-cleanup-resources-cli]
[!div class="nextstepaction"] Connect to Azure Queue Storage