How to install Azure CLI and Azure Functions Core Tools CLI with Homebrew

Verifying Homebrew

$ brew --version

Homebrew 3.2.6
Homebrew/homebrew-core (git revision c4d5aac8ec; last commit 2021-08-07)
Homebrew/homebrew-cask (git revision 1169dcb641; last commit 2021-08-07)

Demo repository is in the following link.

https://github.com/nodejs-projects-kenanhancer/serverless-azure-functions-typescript-demo

Azure CLI

Azure CLI, or Azure Command Line Interface, is a set of commands used to create and manage Azure resources. It is a cross-platform command-line tool that's available for Windows, macOS, and Linux and can be run in the Azure Cloud Shell directly from a web browser.

Azure CLI is designed to be easy to learn and get started with but powerful enough to manage your entire Azure environment. It's optimized for automation and can be used in a DevOps pipeline. You can use Azure CLI to create and manage resources such as virtual machines, storage accounts, and web apps, among others.

Before using Azure CLI, you need to authenticate with your Azure account. You can do this by using the az login command, which opens a web browser for you to sign in with your Azure credentials.

Azure CLI Usage Pattern

$ az [group] [subgroup] [command]

Example – to create a new resource group

$ az group create

Installing

$ brew update && brew install azure-cli

Verifying

$ az --version

azure-cli                         2.26.1 *

core                              2.26.1 *
telemetry                          1.0.6

Python location '/usr/local/Cellar/azure-cli/2.26.1/libexec/bin/python'
Extensions directory '/Users/kenanhancer/.azure/cliextensions'

Python (Darwin) 3.8.11 (default, Jun 29 2021, 03:08:07) 
[Clang 12.0.5 (clang-1205.0.22.9)]

Legal docs and information: aka.ms/AzureCliLegal


You have 2 updates available. Consider updating your CLI installation with 'az upgrade'

Please let us know how we are doing: https://aka.ms/azureclihats
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
Continue reading

Creating Azure Function App for Python with Azure Functions Core Tools CLI

We cannot specify the Python runtime version with FUNCTIONS_EXTENSION_VERSION. The FUNCTIONS_EXTENSION_VERSION setting is specifically for specifying the version of the Azure Functions runtime, not the version of Python.

The Azure Functions runtime is the host that runs your functions. It's a separate concept from the Python runtime. Each version of the Azure Functions runtime has a range of versions of Python (and other languages) that it supports, but you can't use the FUNCTIONS_EXTENSION_VERSION setting to choose a specific Python version.

The version of Python that's used in your function app is typically determined by the environment in which the app is running. When running locally, this will be the version of Python that's available in your local environment. When running in Azure, the Python version is determined by the configuration of your Azure Functions host.

If you want to specify a Python version for local development, you can do so using a Python version management tool like pyenv, and creating a .python-version file in the root of your function app project. For deployment in Azure, you specify the Python version when you create the Function App.

Remember to check the Azure Functions runtime support for your chosen Python version. Azure Functions 4.x runtime supports Python 3.7, 3.8, 3.9 and 3.10 for now.

Prerequisite check for Python

$ az --version
$ az login
$ func --version
$ python --version

Create and activate a virtual environment with virtualenv package manager

virtualenv (for Python 2) and venv (for Python 3) allow you to manage separate package installations for different projects.

$ mkdir azure-demo
$ cd azure-demo
$ pyenv local 3.10.5
$ python -m venv .venv
Continue reading

Azure Functions Basics

Before you begin, you must have the following requirements in place:

Prerequisite check

# to check that the Azure Functions Core Tools are version v4.0.5095 or above.
$ func --version

4.0.5198
# to check that the Azure CLI version is 2.4 or later.
$ az --version

azure-cli                         2.49.0

core                              2.49.0
telemetry                          1.0.8

Dependencies:
msal                              1.20.0
azure-mgmt-resource               22.0.0

Python location '/opt/homebrew/Cellar/azure-cli/2.49.0/libexec/bin/python'
Extensions directory '/Users/kenanhancer/.azure/cliextensions'

Python (Darwin) 3.10.12 (main, Jun  7 2023, 00:38:32) [Clang 14.0.3 (clang-1403.0.22.14.1)]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.
# to sign in to Azure and verify an active subscription.
$ az login

Continue reading