Command line tools for Azure Functions
Перейти к файлу
Naren Soni d59b84bb7d
Adding comment to describe the logic for blob content validation (#3876)
2024-11-08 18:11:43 -08:00
.github Add workflow to review PR dependencies (#4136) 2024-11-04 13:52:41 -08:00
.vscode Specify framework in VS Code publish task (#3799) 2024-10-15 11:04:45 -07:00
build Package Updates (#3885) 2024-10-17 16:37:25 -07:00
eng/ci Update UserSecret E2E Tests (#3846) 2024-10-10 10:24:53 -07:00
publish-scripts Use xz compression for debian 11. (#3645) 2024-04-18 10:08:20 -07:00
src/Azure.Functions.Cli Adding comment to describe the logic for blob content validation (#3876) 2024-11-08 18:11:43 -08:00
test/Azure.Functions.Cli.Tests Set the default PowerShell worker to 7.4 (#3792) 2024-11-07 13:17:25 -08:00
tools Update UserSecret E2E Tests (#3846) 2024-10-10 10:24:53 -07:00
.gitattributes add a build.sh for Linux CI 2018-04-03 11:08:48 -07:00
.gitignore Add support for win-arm64 (#3116) 2022-09-20 15:17:10 -07:00
Azure.Functions.Cli.sln cleaning up nuget configs (#2605) 2021-05-26 10:10:11 -07:00
CODEOWNERS Update CODEOWNERS (#3878) 2024-10-10 10:28:32 -07:00
CONTRIBUTING.md Make a start on a contributing file for the v2 runtime 2018-02-02 09:23:00 -08:00
LICENSE Update license and link in readme. 2017-01-04 09:44:03 -08:00
NuGet.Config New Pipelines (#3701) 2024-06-19 02:28:52 -05:00
README.md add instructions for ubuntu 22.04 (#3727) 2024-07-10 13:45:39 -07:00
SECURITY.md Microsoft mandatory file (#3061) 2022-06-07 16:54:06 -07:00
build.ps1 New Pipelines (#3701) 2024-06-19 02:28:52 -05:00
build.sh Update build.sh 2018-08-07 13:57:33 -07:00
check-vulnerabilities.ps1 restructuring CI to reduce time-to-failure for scanning (#3761) 2024-07-24 13:57:40 -07:00
code-mirror.yml adding core mirroring yml (#3678) 2024-05-13 15:37:14 -05:00
dotnet-install.sh Upgrading to .NET Core 2.1 2018-06-05 16:43:57 -07:00
generateMsiFiles.ps1 Add support for win-arm64 (#3116) 2022-09-20 15:17:10 -07:00
generateSha.ps1 Fixing the sha generation to not add new line in the end 2020-05-12 11:08:38 -07:00
pipelineUtilities.psm1 Core Tools .NET 9 Changes (#3764) 2024-07-31 10:32:35 -07:00
repackageBinaries.ps1 Add support for win-arm64 (#3116) 2022-09-20 15:17:10 -07:00
uploadContentToStorageAccount.ps1 Update the path to upload the Core Tools artifacts for V4 (#2795) 2021-10-27 17:57:32 -07:00
validateWorkerVersions.ps1 Add PowerShell 7.4 language worker for integration testing (#3270) 2023-03-28 11:48:42 -07:00

README.md

Azure Functions Logo

Branch Status
v4.x Build status
v3.x Build status
dev Build Status
v1.x Build status

Azure Functions Core Tools

The Azure Functions Core Tools provide a local development experience for creating, developing, testing, running, and debugging Azure Functions.

Versions

v1 (v1.x branch): Requires .NET 4.7.1 Windows Only

v2 (dev branch): Self-contained cross-platform package

v3: (v3.x branch): Self-contained cross-platform package

v4: (v4.x branch): Self-contained cross-platform package (recommended)

Installing

Windows

To download and install with MSI:

v4
v3

To install with npm:

v4
npm i -g azure-functions-core-tools@4 --unsafe-perm true
v3
npm i -g azure-functions-core-tools@3 --unsafe-perm true
v2
npm i -g azure-functions-core-tools@2 --unsafe-perm true

To install with chocolatey:

v4
choco install azure-functions-core-tools
v3
choco install azure-functions-core-tools-3

Notice: To debug functions under vscode, the 64-bit version is required

choco install azure-functions-core-tools-3 --params "'/x64'"
v2
choco install azure-functions-core-tools-2

To install with winget:

v4
winget install Microsoft.Azure.FunctionsCoreTools
v3
winget install Microsoft.Azure.FunctionsCoreTools -v 3.0.3904

Mac

Homebrew:

v4
brew tap azure/functions
brew install azure-functions-core-tools@4
v3
brew tap azure/functions
brew install azure-functions-core-tools@3
v2
brew tap azure/functions
brew install azure-functions-core-tools@2

Homebrew allows side by side installation of v2 and v3, you can switch between the versions using

brew link --overwrite azure-functions-core-tools@3

Linux

1. Set up package feed

Ubuntu 22.04
wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Ubuntu 20.04
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Ubuntu 19.04
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Ubuntu 18.10
wget -q https://packages.microsoft.com/config/ubuntu/18.10/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Ubuntu 18.04
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Ubuntu 16.04 / Linux Mint 18
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Debian 12
export DEBIAN_VERSION=12

apt-get update && apt-get install gpg wget  -y
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /usr/share/keyrings/microsoft-prod.gpg
wget -q https://packages.microsoft.com/config/debian/$DEBIAN_VERSION/prod.list
mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
chown root:root /usr/share/keyrings/microsoft-prod.gpg
chown root:root /etc/apt/sources.list.d/microsoft-prod.list
apt-get update && apt-get install azure-functions-core-tools-4  -y
apt-get update && apt-get install libicu-dev  -y

2. Install

v4
sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
v3
sudo apt-get update
sudo apt-get install azure-functions-core-tools-3
v2
sudo apt-get update
sudo apt-get install azure-functions-core-tools-2

Other Linux Distributions

  1. Download latest release

    Download the latest release for your platform from here.

  2. 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
    
  3. Make the func command executable

    Zip files do not maintain the executable bit on binaries. So, you'll need to make the func binary, as well as gozip (used by func during packaging) executables. Assuming you used the instructions above to unzip:

    cd azure-functions-cli
    chmod +x func
    chmod +x gozip
    ./func
    
  4. 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.

Getting Started on Kubernetes

Using the Core Tools, you can easily configure a Kubernetes cluster and run Azure Functions on it.

Prerequisites

Installing Kubernetes scalers

This deploys KEDA to your cluster which allows you to deploy your functions in a scale-to-zero by default for non-http scenarios only.

func kubernetes install --namespace {namespace}

KEDA: Handles monitoring polling event sources currently QueueTrigger and ServiceBusTrigger.

Deploy to Kubernetes

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.

Deploy using a private registry

func kubernetes deploy --name myfunction --registry <docker-hub-id or registry-server> --pull-secret <registry auth secret>

Deploy a function to Knative

Prerequisites

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>

Deploying a function to AKS using ACR

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.

Create a AKS cluster

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

Create a ACR Registry

An ACR instance can be created using the Azure Portal or the Azure CLI

Login to the ACR Registry

Before pushing and pulling container images, you must log in to the ACR instance.

az acr login --name <acrName>

Give the AKS cluster access to the ACR Registry

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

Run the deployment

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

Verifying your deployment

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.

Deploying Azure Functions with Virtual-Kubelet

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.

Known Issues:

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/

Default Directories

  • 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.

Telemetry

The Azure Functions Core tools collect usage data in order to help us improve your experience. The data is anonymous and doesn't include any user specific or personal information. The data is collected by Microsoft.

You can opt-out of telemetry by setting the FUNCTIONS_CORE_TOOLS_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Microsoft privacy statement

License

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 opencode@microsoft.com with any additional questions or comments.

Contact Us

For questions on Azure Functions or the tools, you can ask questions here:

File bugs at Azure Functions Core Tools repo on GitHub.