Branch | Status |
---|---|
master | |
dev | |
v1.x |
The Azure Functions Core Tools provide a local development experience for creating, developing, testing, running, and debugging Azure Functions.
v1 (v1.x branch): Requires .NET 4.7.1 Windows Only
v2 (master branch): Self-contained cross-platform package
To install runtime with npm:
npm i -g azure-functions-core-tools --unsafe-perm true
To install with chocolatey:
choco install azure-functions-core-tools
Homebrew:
brew tap azure/functions
brew install azure-functions-core-tools
- Set up package feed
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
wget -q https://packages.microsoft.com/config/ubuntu/18.10/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
- Install
sudo apt-get update
sudo apt-get install azure-functions-core-tools
- Download latest release
Download the latest release for your platform from here.
- Unzip release zip
Using your preferred tool, unzip the downloaded release. To unzip into an azure-functions-cli
directory using the unzip
tool, run this command from the directory containing the downloaded release zip:
unzip -d azure-functions-cli Azure.Functions.Cli.linux-x64.*.zip
- Make the
func
command executable
Zip files do not maintain the executable bit on binaries. So, you'll need to make the func
binary executable. Assuming you used the instructions above to unzip:
cd azure-functions-cli
chmod +x func
./func
- Optionally add
func
to your$PATH
To execute the func
command without specifying the full path to the binary, add its directory to your $PATH
environment variable. Assuming you're still following along from above:
export PATH=`pwd`:$PATH
func
Code and test Azure Functions locally
NOTE: npm can be used on all platforms. On unix platforms, you may need to specify --unsafe-perm
if you are running npm with sudo. That's due to npm behavior of post install script.
NOTE: If you're running the v2 on Windows, Linux, or Mac, make sure to enable the beta
runtime in function app settings, otherwise you may not see the same results as running locally.
Using the Core Tools, you can easily configure a Kubernetes cluster and run Azure Functions on it.
This deploys KEDA and Osiris to your cluster which allows you to deploy your functions in a scale-to-zero by default.
func kubernetes install --namespace {namespace}
KEDA: Handles monitoring polling event sources currently QueueTrigger and ServiceBusTrigger. Osiris:: Handles Http traffic monitoring and on demand scale your deployment to and from 0
First make sure you have Dockerfile for your project. You can generate one using
func init --docker # or --docker-only (for existing projects)
Then to deploy to kubernetes
func kubernetes deploy \
--name myfunction \
--namespace functions-ns \
--registry <docker-hub-id or registry-server>
This will build the current Dockerfile
and push the image to the registry specified, then deploys a Secret
, Deployment
, and ScaledObject
. If your functions have httpTrigger, you'll get an additional Deployment
and Service
.
func kubernetes deploy --name myfunction --registry <docker-hub-id or registry-server> --pull-secret <registry auth secret>
Deploying Azure Functions to knative is supported with the --platform knative
flag.
The Core Tools CLI identifies non HTTP trigger functions and annotates the knative manifest with the the minScale
annotation to opt out of scale-to-zero.
func deploy --platform knative --name myfunction --registry <docker-hub-id or registry-server>
Using the configuration options an Azure Function app can also be deployed to a AKS (Azure Kubernetes Service) Kubernetes cluster and use ACR as the registry server. Do all of the following before you run the deployment command.
You can create an AKS cluster using the Azure Portal or using Azure CLI.
Once your AKS cluster is created make sure that you can access it using kubectl. To make kubectl run in the context of your cluster, configure a connection using the command below.
az aks get-credentials \
--name FunctionsCluster \
--resource-group <resource-group-name>
To verify the connection to your cluster run the following command
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-agentpool-20257154-0 Ready agent 1d v1.11.5
aks-agentpool-20257154-1 Ready agent 1d v1.11.5
aks-agentpool-20257154-2 Ready agent 1d v1.11.5
An ACR instance can be created using the Azure Portal or the Azure CLI
Before pushing and pulling container images, you must log in to the ACR instance.
az acr login --name <acrName>
The AKS cluster needs access to the ACR Registry to pull the container. Azure creates a service principal to support cluster operability with other Azure resources. This can be used for authentication with an ACR registry. See here for how to grant the right access here: Authenticate with Azure Container Registry from Azure Kubernetes Service
The deployment will build the docker container and upload the container image to your referenced ACR instance (Note: Specify the ACR Login Server in the --registry parameter this is usually of the form <container_registry_name>.azurecr.io) and then your AKS cluster will use that as a source to obtain the container and deploy it.
func kubernetes deploy --name myfunction --registry <acr-registry-loginserver>
If the deployment is successful, you should see this:
Function deployed successfully! Function IP: 40.121.21.192
You can verify your deployment by using the Kubernetes web dashboard. To start the Kubernetes dashboard, use the az aks browse command.
az aks browse --resource-group myResourceGroup --name myAKSCluster
In the Kubernetes dashboard look for the namespace "azure-functions" and make sure that a pod has been deployed sucessfully with your container.
Azure Functions running on Kubernetes can take advantage of true serverless containers model by getting deployed to different providers of Virtual Kubelet, such as Azure Container Instances.
Functions deployed to Kubernetes already contain all the tolerations needed to be schedulable to Virtual Kubelet nodes. All you need to do is to set up VKubelet on your Kubernetes cluster:
Important note: Virtual Kubelet does not currently allow for Kubernetes Services to route external traffic to pods. This means that HTTP triggered functions will not receive traffic running on a VKubelet provider (including ACI).
A good usage scenario for using functions with VKubelet would be with event triggered / time triggered functions that do not rely on external HTTP traffic.
func extensions
command require the dotnet
cli to be installed and on your path. This requirement is tracked here. You can install .NET Core for your platform from https://www.microsoft.com/net/download/
CurrentDirectory
: is the default directory the functions runtime looks for functions in.%TMP%\LogFiles\Application\Functions
: is the default directory for logs. It mirrors the logs directory on Azure as well.
This project is under the benevolent umbrella of the .NET Foundation and is licensed under the MIT License
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
For questions on Azure Functions or the tools, you can ask questions here:
File bugs at Azure Functions Core Tools repo on GitHub.