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

How to install Python packages with pipenv, venv or virtualenv package manager

You can find GitHub repository in https://github.com/python-projects-kenanhancer/python_demo

  • Pyenv – Python Runtime Version Manager
    – to install, uninstall, list or switch between different python runtimes
  • Pipenv – Python Package Manager and Virtual environment manager
    – to create an isolated virtual environment with a specific python runtime
    – to install, uninstall, list python packages
  • Venv – Virtual environment manager (for Python 3)
    – to create an isolated virtual environment with a specific python runtime
    – python packages will be isolated already
  • Virtualenv – Virtual environment manager (for Python 2)
    – to create an isolated virtual environment with a specific python runtime
    – python packages will be isolated already

Installing Python Runtime Versions via Pyenv

In order to test different Python Runtime versions, I have installed some versions.

$ pyenv install 3.10.2
$ pyenv install 3.10.3
$ pyenv install 3.10.4
$ pyenv install 3.10.5

I have 4 Python runtime versions(3.10.2, 3.10.3, 3.10.4, 3.10.5) in my machine. So, let's list them.

$ pyenv versions

  system
  3.10.2
  3.10.3
  3.10.4
* 3.10.5 (set by /Users/kenanhancer/.pyenv/version)
Continue reading

How to install AWS CLI with Homebrew

Installing

Run the following code to install Homebrew if you don't have in your machine.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Verifying

Run the following code to verify Homebrew is installed

$ 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)

AWS CLI

AWS CLI, or Amazon Web Services Command Line Interface, is a unified tool that allows you to manage and interact with AWS services from the command line. It provides direct access to public APIs for AWS services. You can use the AWS CLI for a wide range of functions, from launching and controlling EC2 instances, to creating S3 buckets, and more.

Like Azure CLI, the AWS CLI is also cross-platform and supports Windows, macOS, and Linux. It's often used for scripting and automation tasks, making it a valuable tool for system administrators and DevOps professionals.

AWS CLI Usage Pattern

$ aws [service] [operation] [parameters]

Example – to list all S3 buckets

$ aws s3 ls

Installing

$ brew update && brew install awscli

Verifying

$ aws --version

aws-cli/2.2.27 Python/3.9.6 Darwin/20.6.0 source/x86_64 prompt/off

Upgrading

$ brew upgrade awscli

Uninstalling

$ brew uninstall awscli

Using AWS CLI

Create default profile

$ aws configure

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: aJwerXUtnFEMI/K7MDENG/EXAMPLEKEY
Default region name [None]: eu-west-2
Default output format [None]: json

Create Named Profiles

$ aws configure --profile kenan-dev

AWS Access Key ID [None]: KAKAI44Q33DHBEXAMPLE
AWS Secret Access Key [None]: qwertGbClwBF/2Zp9Utk/EXAMPLEKEY
Default region name [None]: eu-west-2
Default output format [None]: json

List AWS Profiles

$ aws configure list-profiles

List AWS Configuration Data

$ aws configure list
$ aws configure list --profile kenan-dev

Set any credential or configuration settings

$ aws configure set aws_access_key_id bar --profile default
$ aws configure set aws_secret_access_key foo --profile kenan-dev

Get any credential or configuration settings

$ aws configure get aws_access_key_id --profile default
$ aws configure get region --profile kenan-dev

AWS SAM CLI

The AWS SAM(Serverless Application Model) CLI is a command-line tool that makes it easier for developers to create, deploy, and test serverless applications using AWS.

With AWS SAM CLI, you can define serverless applications that use several other AWS resources, not just AWS Lambda functions. Here are some examples:

  • API Gateway: You can define APIs in your SAM template that AWS will create using Amazon API Gateway.
  • DynamoDB Tables: You can define DynamoDB tables in your SAM template.
  • S3 Buckets: You can define Amazon S3 buckets in your SAM template.
  • EventBridge Events: You can define EventBridge events in your SAM template.
  • Step Functions: You can define state machines in your SAM template that AWS will create using AWS Step Functions.
  • SNS Topics, SQS Queues: You can define Simple Notification Service (SNS) topics and Simple Queue Service (SQS) queues in your SAM template, and much more.

Additionally, AWS SAM CLI helps in building, packaging, deploying, and testing serverless applications defined by SAM templates. It supports step-through debugging of your serverless applications, tailing logs of Lambda functions, generating sample payloads for various event sources, and validating SAM templates, amongst other things.

So, while AWS Lambda functions are a key component of many serverless applications, AWS SAM CLI offer a broader range of capabilities for defining, developing, and managing serverless applications on AWS.

Find more details about installation in https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html

Installing

$ brew tap aws/tap
$ brew install aws-sam-cli

Verifying

$ sam --version

SAM CLI, version 1.27.2

Upgrading

$ brew upgrade aws-sam-cli

Uninstalling

$ brew uninstall aws-sam-cli

How to install Python with pyenv version manager

I am using different programming languages like C#, Java, Node.js etc and need to manage runtime versions in my local. So, I like to use runtime version managers.

For example, there are some runtime version managers in Node.js community like nvm or n.

Let's say I work for one Node.js project in dev machine with Node v8.0.0 but other project needs Node v6.0.0

In order to handle, different versions in same machine, we may use runtime version managers.

I just want to find a way to switch between different Python runtime version so that found pyenv runtime version manager.

Pyenv is a simple, powerful and cross-platform tool for managing multiple versions of Python on a single machine. It is very useful when you need to switch between different Python versions for different projects, or when different applications on your system require different Python versions.

So, we can install, uninstall, list or switch between different versions.

Pyenv installation

Click pyenv link for more detailed installation.

Installing pyenv with Homebrew

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my post.

Run the following commands in your terminal. But, just copy commands without $ sign.

$ brew update
$ brew install pyenv

Setting PATH

Checking shell

output of echo $SHELL can be bash, zsh or fish

$ echo $SHELL

/usr/local/bin/bash

# OR

/bin/zsh

Run the following command for bash, zsh, etc configuration.

$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc

and restart your terminal manually or run the following command to restart automatically.

$ exec "$SHELL"

Upgrading pyenv

$ brew upgrade pyenv

Uninstall pyenv

$ rm -rf $(pyenv root)
$ brew uninstall pyenv

Pyenv commands

List all Python versions installed in system

$ pyenv versions

  system
  3.7.3
* 3.8.2 (set by /Users/kenanhancer/.pyenv/version)

Show current active Python version in system

$ pyenv version

3.8.2 (set by /Users/kenanhancer/.pyenv/version)
Continue reading