Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure Functions Core Tools lets you develop and test your functions on your local computer. When you're ready, you can also use Core Tools to deploy your code project to Azure and work with application settings.
You're viewing the C# version of this article. Make sure to select your preferred Functions programming language at the top of the article.
If you want to get started right away, complete the Core Tools quickstart article.
You're viewing the Java version of this article. Make sure to select your preferred Functions programming language at the top of the article.
If you want to get started right away, complete the Core Tools quickstart article.
You're viewing the JavaScript version of this article. Make sure to select your preferred Functions programming language at the top of the article.
If you want to get started right away, complete the Core Tools quickstart article.
You're viewing the PowerShell version of this article. Make sure to select your preferred Functions programming language at the top of the article.
If you want to get started right away, complete the Core Tools quickstart article.
You're viewing the Python version of this article. Make sure to select your preferred Functions programming language at the top of the article.
If you want to get started right away, complete the Core Tools quickstart article.
You're viewing the TypeScript version of this article. Make sure to select your preferred Functions programming language at the top of the article.
If you want to get started right away, complete the Core Tools quickstart article.
The recommended way to install Core Tools depends on the operating system of your local development computer.
The following steps use APT to install Core Tools on your Ubuntu/Debian Linux distribution. For other Linux distributions, see the Core Tools readme.
Install the Microsoft package repository GPG key, to validate package integrity:
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
Set up the APT source list before doing an APT update.
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs 2>/dev/null)-prod $(lsb_release -cs 2>/dev/null) main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs 2>/dev/null | cut -d'.' -f 1)/prod $(lsb_release -cs 2>/dev/null) main" > /etc/apt/sources.list.d/dotnetdev.list'
Check the /etc/apt/sources.list.d/dotnetdev.list
file for one of the appropriate Linux version strings in the following table:
Linux distribution | Version |
---|---|
Debian 12 | bookworm |
Debian 11 | bullseye |
Debian 10 | buster |
Debian 9 | stretch |
Ubuntu 22.04 | jammy |
Ubuntu 20.04 | focal |
Ubuntu 19.04 | disco |
Ubuntu 18.10 | cosmic |
Ubuntu 18.04 | bionic |
Ubuntu 17.04 | zesty |
Ubuntu 16.04/Linux Mint 18 | xenial |
Start the APT source update:
sudo apt-get update
Install the Core Tools package:
sudo apt-get install azure-functions-core-tools-4
For help with version-related issues, see Core Tools versions.
Important
For Python, you must run Core Tools commands in a virtual environment. For more information, see Quickstart: Create a Python function in Azure from the command line.
In the terminal window or from a command prompt, run the following command to create a project in the MyProjFolder
folder:
func init MyProjFolder --worker-runtime dotnet-isolated
By default this command creates a project that runs in-process with the Functions host on the current Long-Term Support (LTS) version of .NET Core. You can use the --target-framework
option to target a specific supported version of .NET, including .NET Framework. For more information, see the func init
reference.
For a comparison between the two .NET process models, see the process mode comparison article.
Java uses a Maven archetype to create the local project, along with your first HTTP triggered function. Rather than using func init
and func new
, you should instead follow the steps in the Command line quickstart.
This command creates a JavaScript project that uses the desired programming model version.
This command creates a TypeScript project that uses the desired programming model version.
func init MyProjFolder --worker-runtime powershell
This command creates a Python project that uses the desired programming model version.
When you run func init
without the --worker-runtime
option, you're prompted to choose your project language. To learn more about the available options for the func init
command, see the func init
reference.
To add a function to your project, run the func new
command using the --template
option to select your trigger template. The following example creates an HTTP trigger named MyHttpTrigger
:
func new --template "Http Trigger" --name MyHttpTrigger
This example creates a Queue Storage trigger named MyQueueTrigger
:
func new --template "Azure Queue Storage Trigger" --name MyQueueTrigger
The following considerations apply when adding functions:
When you run func new
without the --template
option, you're prompted to choose a template.
Use the func templates list
command to see the complete list of available templates for your language.
When you add a trigger that connects to a service, you'll also need to add an application setting that references a connection string or a managed identity to the local.settings.json file. Using app settings in this way prevents you from having to embed credentials in your code. For more information, see Work with app settings locally.
To learn more about the available options for the func new
command, see the func new
reference.
Functions provides a set of service-specific input and output bindings, which make it easier for your function to connection to other Azure services without having to use the service-specific client SDKs. For more information, see Azure Functions triggers and bindings concepts.
To add an input or output binding to an existing function, you must manually update the function definition.
The following example shows the function definition after adding a Queue Storage output binding to an HTTP triggered function:
Because an HTTP triggered function also returns an HTTP response, the function returns a MultiResponse
object, which represents both the HTTP and queue output.
[Function("HttpExample")]
public static MultiResponse Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
FunctionContext executionContext)
{
This example is the definition of the MultiResponse
object that includes the output binding:
public class MultiResponse
{
[QueueOutput("outqueue",Connection = "AzureWebJobsStorage")]
public string[] Messages { get; set; }
public IActionResult HttpResponse { get; set; }
}
When applying that example to your own project, you might need to change HttpRequest
to HttpRequestData
and IActionResult
to HttpResponseData
, depending on if you are using ASP.NET Core integration or not.
Messages are sent to the queue when the function completes. The way you define the output binding depends on your process model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.
@FunctionName("HttpExample")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
@QueueOutput(name = "msg", queueName = "outqueue",
connection = "AzureWebJobsStorage") OutputBinding<String> msg,
final ExecutionContext context) {
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
The way you define the output binding depends on the version of your Node.js model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.
$outputMsg = $name
Push-OutputBinding -name msg -Value $outputMsg
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
@app.route(route="HttpExample")
@app.queue_output(arg_name="msg", queue_name="outqueue", connection="AzureWebJobsStorage")
def HttpExample(req: func.HttpRequest, msg: func.Out [func.QueueMessage]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
The way you define the output binding depends on the version of your Python model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.
The way you define the output binding depends on the version of your Node.js model. For more information, including links to example binding code that you can refer to, see Add bindings to a function.
The following considerations apply when adding bindings to a function:
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
For more information, including links to example binding code that you can refer to, see Add bindings to a function.
Before you can run or debug the functions in your project, you need to start the Functions host from the root directory of your project. The host enables triggers for all functions in the project. Use this command to start the local runtime:
mvn clean package
mvn azure-functions:run
func start
func start
npm install
npm start
This command must be run in a virtual environment.
When the Functions host starts, it outputs a list of functions in the project, including the URLs of any HTTP-triggered functions, like in this example:
Found the following functions: Host.Functions.MyHttpTrigger Job host started Http Function MyHttpTrigger: http://localhost:7071/api/MyHttpTrigger
Keep in mind the following considerations when running your functions locally:
By default, authorization isn't enforced locally for HTTP endpoints. This means that all local HTTP requests are handled as authLevel = "anonymous"
. For more information, see Authorization level. You can use the --enableAuth
option to require authorization when running locally. For more information, see func start
You can use the local Azurite emulator when locally running functions that require access to Azure Storage services (Queue Storage, Blob Storage, and Table Storage) without having to connect to these services in Azure. When using local emulation, make sure to start Azurite before starting the local host (func.exe). For more information, see Local storage emulation.
You can trigger non-HTTP functions locally without connecting to a live service. For more information, see Run a local function.
When you include your Application Insights connection information in the local.settings.json file, local log data is written to the specific Application Insights instance. To keep local telemetry data separate from production data, consider using a separate Application Insights instance for development and testing.
func host start
command to start the local runtime.With your local Functions host (func.exe) running, you can now trigger individual functions to run and debug your function code. The way in which you execute an individual function depends on its trigger type.
Note
Examples in this topic use the cURL tool to send HTTP requests from the terminal or a command prompt. You can use a tool of your choice to send HTTP requests to the local server. The cURL tool is available by default on Linux-based systems and Windows 10 build 17063 and later. On older Windows, you must first download and install the cURL tool.
HTTP triggers are started by sending an HTTP request to the local endpoint and port as displayed in the func.exe output, which has this general format:
http://localhost:<PORT>/api/<FUNCTION_NAME>
In this URL template, <FUNCTION_NAME>
is the name of the function or route and <PORT>
is the local port on which func.exe is listening.
For example, this cURL command triggers the MyHttpTrigger
quickstart function from a GET request with the name parameter passed in the query string:
curl --get http://localhost:7071/api/MyHttpTrigger?name=Azure%20Rocks
This example is the same function called from a POST request passing name in the request body, shown for both Bash shell and Windows command line:
curl --request POST http://localhost:7071/api/MyHttpTrigger --data '{"name":"Azure Rocks"}'
curl --request POST http://localhost:7071/api/MyHttpTrigger --data "{'name':'Azure Rocks'}"
The following considerations apply when calling HTTP endpoints locally:
You can make GET requests from a browser passing data in the query string. For all other HTTP methods, you must use a HTTP testing tool that also keeps your data secure. For more information, see HTTP test tools.
Make sure to use the same server name and port that the Functions host is listening on. You see an endpoint like this in the output generated when starting the Function host. You can call this URL using any HTTP method supported by the trigger.
The Azure Functions Core Tools supports three types of deployment:
Deployment type | Command | Description |
---|---|---|
Project files | func azure functionapp publish |
Deploys function project files directly to your function app using zip deployment. |
Azure Container Apps | func azurecontainerapps deploy |
Deploys a containerized function app to an existing Container Apps environment. |
Kubernetes cluster | func kubernetes deploy |
Deploys your Linux function app as a custom Docker container to a Kubernetes cluster. |
You must have either the Azure CLI or Azure PowerShell installed locally to be able to publish to Azure from Core Tools. By default, Core Tools uses these tools to authenticate with your Azure account.
If you don't have these tools installed, you need to instead get a valid access token to use during deployment. You can present an access token using the --access-token
option in the deployment commands.
To publish your local code to a function app in Azure, use the func azure functionapp publish
command, as in the following example:
func azure functionapp publish <FunctionAppName>
This command publishes project files from the current directory to the <FunctionAppName>
as a .zip deployment package. If the project requires compilation, it's done remotely during deployment.
Java uses Maven to publish your local project to Azure instead of Core Tools. Use the following Maven command to publish your project to Azure:
mvn azure-functions:deploy
When you run this command, Azure resources are created during the initial deployment based on the settings in your pom.xml file. For more information, see Deploy the function project to Azure.
The following considerations apply to this kind of deployment:
Publishing overwrites existing files in the remote function app deployment.
You must have already created a function app in your Azure subscription. Core Tools deploys your project code to this function app resource. To learn how to create a function app from the command prompt or terminal window using the Azure CLI or Azure PowerShell, see Create a Function App for serverless execution. You can also create these resources in the Azure portal. You get an error when you try to publish to a <FunctionAppName>
that doesn't exist in your subscription.
A project folder may contain language-specific files and directories that shouldn't be published. Excluded items are listed in a .funcignore file in the root project folder.
By default, your project is deployed so that it runs from the deployment package. To disable this recommended deployment mode, use the --nozip
option.
A remote build is performed on compiled projects. This can be controlled by using the --no-build
option.
Use the --publish-local-settings
option to automatically create app settings in your function app based on values in the local.settings.json file.
To publish to a specific named slot in your function app, use the --slot
option.
Core Tools lets you deploy your containerized function app to both managed Azure Container Apps environments and Kubernetes clusters that you manage.
Use the following func azurecontainerapps deploy
command to deploy an existing container image to a Container Apps environment:
func azurecontainerapps deploy --name <APP_NAME> --environment <ENVIRONMENT_NAME> --storage-account <STORAGE_CONNECTION> --resource-group <RESOURCE_GROUP> --image-name <IMAGE_NAME> [--registry-password] [--registry-server] [--registry-username]
When you deploy to an Azure Container Apps environment, the following considerations apply:
The environment and storage account must already exist. The storage account connection string you provide is used by the deployed function app.
You don't need to create a separate function app resource when deploying to Container Apps.
Storage connection strings and other service credentials are important secrets. Make sure to securely store any script files using func azurecontainerapps deploy
and don't store them in any publicly accessible source control systems. You can encrypt the local.settings.json file for added security.
For more information, see Azure Container Apps hosting of Azure Functions.
When running in a function app in Azure, settings required by your functions are stored securely in app settings. During local development, these settings are instead added to the Values
collection in the local.settings.json file. The local.settings.json file also stores settings used by local development tools.
Items in the Values
collection in your project's local.settings.json file are intended to mirror items in your function app's application settings in Azure.
The following considerations apply when working with the local settings file:
Because the local.settings.json may contain secrets, such as connection strings, you should never store it in a remote repository. Core Tools helps you encrypt this local settings file for improved security. For more information, see Local settings file. You can also encrypt the local.settings.json file for added security.
By default, local settings aren't migrated automatically when the project is published to Azure. Use the --publish-local-settings
option when you publish your project files to make sure these settings are added to the function app in Azure. Values in the ConnectionStrings
section are never published. You can also upload settings from the local.settings.json file at any time.
You can download and overwrite settings in your local.settings.json file with settings from your function app in Azure. For more information, see Download application settings.
AzureWebJobsStorage
and a local storage emulator isn't being used, an error is shown. You can use Core Tools to download a specific connection string from any of your Azure Storage accounts.From the project root, use the following command to download all application settings from the myfunctionapp12345
app in Azure:
func azure functionapp fetch-app-settings myfunctionapp12345
This command overwrites any existing settings in the local.settings.json file with values from Azure. When not already present, new items are added to the collection. For more information, see the func azure functionapp fetch-app-settings
command.
Core Tools also make it easy to get the connection string of any storage account to which you have access. From the project root, use the following command to download the connection string from a storage account named mystorage12345
.
func azure storage fetch-connection-string mystorage12345
This command adds a setting named mystorage12345_STORAGE
to the local.settings.json file, which contains the connection string for the mystorage12345
account. For more information, see the func azure storage fetch-connection-string
command.
For improved security during development, consider encrypting the local.settings.json file.
When you publish your project files to Azure without using the --publish-local-settings
option, settings in the local.settings.json file aren't set in your function app. You can always rerun the func azure functionapp publish
with the --publish-settings-only
option to upload just the settings without republishing the project files.
The following example uploads just settings from the Values
collection in the local.settings.json file to the function app in Azure named myfunctionapp12345
:
func azure functionapp publish myfunctionapp12345 --publish-settings-only
To improve security of connection strings and other valuable data in your local settings, Core Tools lets you encrypt the local.settings.json file. When this file is encrypted, the runtime automatically decrypts the settings when needed the same way it does with application setting in Azure. You can also decrypt a locally encrypted file to work with the settings.
Use the following command to encrypt the local settings file for the project:
func settings encrypt
Use the following command to decrypt an encrypted local setting, so that you can work with it:
func settings decrypt
When the settings file is encrypted and decrypted, the file's IsEncrypted
setting also gets updated.
Functions triggers and bindings are implemented as .NET extension (NuGet) packages. To be able to use a specific binding extension, that extension must be installed in the project.
This section doesn't apply to version 1.x of the Functions runtime. In version 1.x, supported bindings were included in the core product extension.
For C# class library projects, add references to the specific NuGet packages for the binding extensions required by your functions. C# script (.csx) project must use extension bundles.
Functions provides extension bundles to make is easy to work with binding extensions in your project. Extension bundles, which are versioned and defined in the host.json file, install a complete set of compatible binding extension packages for your app. Your host.json should already have extension bundles enabled. If for some reason you need to add or update the extension bundle in the host.json file, see Extension bundles.
If you must use a binding extension or an extension version not in a supported bundle, you need to manually install extensions. For such rare scenarios, see the func extensions install
command.
Major versions of Azure Functions Core Tools are linked to specific major versions of the Azure Functions runtime. For example, version 4.x of Core Tools supports version 4.x of the Functions runtime. This version is the recommended major version of both the Functions runtime and Core Tools. You can determine the latest release version of Core Tools in the Azure Functions Core Tools repository.
Starting with version 4.0.6517 of the Core Tools, in-process model projects must reference version 4.5.0 or later of Microsoft.NET.Sdk.Functions
. If an earlier version is used, the func start
command will error.
Run the following command to determine the version of your current Core Tools installation:
func --version
Unless otherwise noted, the examples in this article are for version 4.x.
The following considerations apply to Core Tools installations:
You can only install one version of Core Tools on a given computer.
When upgrading to the latest version of Core Tools, you should use the same method that you used for original installation to perform the upgrade. For example, if you used an MSI on Windows, uninstall the current MSI and install the latest one. Or if you used npm, rerun the npm install command
.
Version 2.x and 3.x of Core Tools were used with versions 2.x and 3.x of the Functions runtime, which have reached their end of support. For more information, see Azure Functions runtime versions overview.
Learn how to develop, test, and publish Azure functions by using Azure Functions core tools. Azure Functions Core Tools is open source and hosted on GitHub. To file a bug or feature request, open a GitHub issue.
Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.