title | description | services | keywords | author | ms.author | ms.assetid | ms.date | ms.topic | ms.service | ms.custom | ms.devlang | manager |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Create your first function from the Azure CLI | Microsoft Docs |
Learn how to create your first Azure Function for serverless execution using the Azure CLI. |
functions |
ggailey777 |
glenga |
674a01a7-fd34-4775-8b69-893182742ae0 |
11/08/2017 |
quickstart |
functions |
mvc |
azure-cli |
cfowler |
This quickstart topic walks you through how to use Azure Functions to create your first function. You use the Azure CLI to create a function app, which is the serverless infrastructure that hosts your function. The function code itself is deployed from a GitHub sample repository.
You can follow the steps below using a Mac, Windows, or Linux computer.
Before running this sample, you must have the following:
- An active GitHub account.
- An active Azure subscription.
[!INCLUDE quickstarts-free-trial-note]
[!INCLUDE cloud-shell-try-it.md]
If you choose to install and use the CLI locally, this topic requires the Azure CLI version 2.0 or later. Run az --version
to find the version you have. If you need to install or upgrade, see Install Azure CLI 2.0.
[!INCLUDE functions-create-resource-group]
[!INCLUDE functions-create-storage-account]
You must have a function app to host the execution of your functions. The function app provides an environment for serverless execution of your function code. It lets you group functions as a logic unit for easier management, deployment, and sharing of resources. Create a function app by using the az functionapp create command.
In the following command, substitute a unique function app name where you see the <app_name>
placeholder and the storage account name for <storage_name>
. The <app_name>
is used as the default DNS domain for the function app, and so the name needs to be unique across all apps in Azure. The deployment-source-url parameter is a sample repository in GitHub that contains a "Hello World" HTTP triggered function.
az functionapp create --name <app_name> --storage-account <storage_name> --resource-group myResourceGroup \
--consumption-plan-location westeurope --deployment-source-url https://github.com/Azure-Samples/functions-quickstart
Setting the consumption-plan-location parameter means that the function app is hosted in a Consumption hosting plan. In this plan, resources are added dynamically as required by your functions and you only pay when functions are running. For more information, see Choose the correct hosting plan.
After the function app has been created, the Azure CLI shows information similar to the following example:
{
"availabilityState": "Normal",
"clientAffinityEnabled": true,
"clientCertEnabled": false,
"containerSize": 1536,
"dailyMemoryTimeQuota": 0,
"defaultHostName": "quickstart.azurewebsites.net",
"enabled": true,
"enabledHostNames": [
"quickstart.azurewebsites.net",
"quickstart.scm.azurewebsites.net"
],
....
// Remaining output has been truncated for readability.
}
[!INCLUDE functions-test-function-code]
[!INCLUDE functions-cleanup-resources]
[!INCLUDE functions-quickstart-next-steps-cli]