title | description | services | keywords | author | ms.author | ms.date | ms.topic | ms.service | ms.custom | ms.devlang | manager |
---|---|---|---|---|---|---|---|---|---|---|---|
Create your first function on Linux in Azure |
Learn how to create your first function hosted on Linux in Azure using the Azure Functions Core Tools and the Azure CLI. |
functions |
ggailey777 |
glenga |
09/12/2018 |
quickstart |
azure-functions |
mvc |
multiple |
jeconnoc |
Azure Functions lets you execute your code in a serverless Linux environment without having to first create a VM or publish a web application. Linux-hosting is currently in preview and requires the Functions 2.0 runtime.
This quickstart article walks you through how to use the Azure CLI to create your first function app running on Linux. The function code is created locally and then deployed to Azure by using the Azure Functions Core Tools.
The following steps are supported on a Mac, Windows, or Linux computer. This article shows you how to create functions in either JavaScript or C#.
Before running this sample, you must have the following:
-
Install Azure Core Tools version 2.x.
-
Install the Azure CLI. This article requires the Azure CLI version 2.0 or later. Run
az --version
to find the version you have. You can also use the Azure Cloud Shell. -
An active Azure subscription.
[!INCLUDE quickstarts-free-trial-note]
Run the following command from the command line to create a function app project in the MyFunctionProj
folder of the current local directory. A GitHub repo is also created in MyFunctionProj
.
func init MyFunctionProj
When prompted, use the arrow keys to select a worker runtime from the following language choices:
dotnet
: creates a .NET class library project (.csproj).node
: creates a JavaScript project.
Writing .gitignore
Writing host.json
Writing local.settings.json
Initialized empty Git repository in C:/functions/MyFunctionProj/.git/
[!INCLUDE functions-create-function-core-tools]
[!INCLUDE functions-update-function-code]
[!INCLUDE functions-run-function-test-local]
[!INCLUDE functions-create-resource-group]
[!INCLUDE functions-create-storage-account]
You must have a function app to host the execution of your functions on Linux. The function app provides a serverless environment for executing your function code. It lets you group functions as a logic unit for easier management, deployment, and sharing of resources. Create a function app running on Linux by using the az functionapp create command.
In the following command, use a unique function app name where you see the <app_name>
placeholder and the storage account name for <storage_name>
. The <app_name>
is also the default DNS domain for the function app. This name needs to be unique across all apps in Azure.
az functionapp create --name <app_name> --storage-account <storage_name> --resource-group myResourceGroup \
--location "westus" --is-linux
Note
If you have an existing resource group named myResourceGroup
with any non-Linux App Service apps, you must use a different resource group. You can't host both Windows and Linux apps in the same resource group.
After the function app has been created, you see the following message:
Your serverless Linux function app 'myfunctionapp' has been successfully created.
To active this function app, publish your app content using Azure Functions Core Tools or the Azure portal.
Now, you can publish your project to the new function app in Azure.
[!INCLUDE functions-publish-project]
[!INCLUDE functions-test-function-code]
[!INCLUDE functions-cleanup-resources]
This article showed you how to host your function app on a default Azure App Service container. You can also host your functions on Linux in your own custom container.
[!div class="nextstepaction"] Create a function on Linux using a custom image