Return to site

Azure Cli Download Mac

broken image


Sponsored By
  1. Install Azure Cli Mac
  2. Azure Cli Download Mac High Sierra
  3. Azure Cli Download Mac Download
  4. Azure Cli Download Mac 10.10

I blogged about the Windows Azure cloud a few weeks ago. I'm digging the new stuff and trying different scenarios on Macs, PCs and Linux (I prefer Ubuntu). As a long time PowerShell and Command Line fan I'm always looking for ways to do stuff 'in text mode' as well as scripting site creations and deployments.

Turns out there are a mess of ways to access Azure from the command line - more than even I thought. There's a JSON-based Web API that these tools end up talking to. You could certainly call that API directly if you wanted, but the command line tools are damn fun.

You can install the Mac Azure SDK installer to get the tools and more on a Mac, or if you install node.js on Windows or Mac or Linux you can use the Node Package Manager (npm) to install Azure tools like this:

You can also use apt-get or other repository commands. After this, you can just run 'azure' which gives you these commands that you link together in a very intuitive way, 'azure topic(noun)verb option' so 'azure site list' or 'azure vm disk create' and the like.

There's even ASCII art, and who doesn't like that. ;)

Using the CLI for Microsoft 365, you can manage your Microsoft 365 tenant and SharePoint Framework projects on any platform. No matter if you are on Windows, macOS or Linux, using Bash, Cmder or PowerShell, using the CLI for Microsoft 365 you can configure Microsoft 365, manage SharePoint Framework projects and build automation scripts.

Seriously, though, it's slick. Here's a sample interaction I did just now. I trimmed some boring stuff but this is starting from a fresh machine with no tools and ending with me interacting with my Windows Azure account.

Here's how I can create and start a VM from the command line. First I'll list the available images I can start with, then I create it. I wait for it to get ready, then it's started and ready to remote (RDP, SSH, etc) into.

  • Databricks comes with a CLI tool that provides a way to interface with resources in Azure Databricks. It's built on top of the Databricks REST API and can be used with the Workspace, DBFS, Jobs.
  • However i need to set up this same process on a mac. I have installed the Azure CLI tools and have created the following batch copy command. I have dryrun while i was testing. When you use Azure CLi, you should use%20 to replace it. Cannot download BLOBs from Azure Storage using AzCopy. Copy Azure Blob With Snapshots.

That's the command line tool for Mac, Linux, and optionally Windows (if you install node and run 'npm install azure --global') and there's PowerShell commands for the Windows admin. It's also worth noting that you can check out all the code for these as they are all open source and up on github at http://github.com/windowsazure. The whole command line app is written in JavaScript, in fact.

Just as the command line version of the management tools has a very specific and comfortable noun/verb/options style, the cmdlets are very 'PowerShelly' and will feel comfortable folks who are used to PowerShell. The documentation and tools are in a Preview mode and are under ongoing development, so you'll find some holes in the documentation.

The PowerShell commands all work together and data is passed between them. Here a new Azure VM configuration is created while the VM Name is pull from the list, then the a provisioning config object is passed into New-AzureVM.

Next, I want to figure out how I can spin up a whole farm of websites from the command line, deploy an app to the new web farm, configure the farm for traffic, then load test it hard, all from the command line. Such fun!

Sponsor: I want to thank the folks at DevExpress for sponsoring this week's feed. Check out their DXperience tools, they are amazing. You can create web-based iPad apps with ASP.NET and Web Forms. I was personally genuinely impressed. Introducing DXperience 12.1 by DevExpress - The technology landscape is changing and new platforms are emerging. New tools by DevExpress deliver next-generation user experiences on the desktop, on the Web or across a broad array of Touch-enabled mobile devices.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.


AboutNewsletter

The Azure REST APIs require a Bearer Token Authorization header. The docs do a great job explaining every authentication requirement, but do not tell you how to quickly get started. This post will hopefully solve that for you.

We'll first create an Azure Active Directory Service Principal and use it in Postman to generate a Bearer Token and then call the Azure REST APIs.

Azure Setup

Azure cli download command

Note that the below configuration uses the default Service Principal configuration values. In a production application you are going to want to configure the Service Principal to be constrained to specific areas of your Azure resources. You can find more info on the configuration options in the Azure CLI Service Principal Documentation.

Get the Azure CLI

Install Azure Cli Mac

You have two options when executing Azure CLI commands:

Azure Cloud Shell

Go to Azure Cloud Shell

Local with Azure CLI

Install Azure CLI 2.0

Login

If a browser doesn't automatically open, go to http://aka.ms/devicelogin and enter the code show in the console.

Set Active Subscription

Create Service Principal

Copy this output to a temp location, you will need the values in a minute.

Azure Cli Download Mac

Service Principal Password Reset

You can execute the following command if you ever need to reset your Service Principal password.

You can read more about Service Principals here.

Postman Setup

We are now going to use Postman to execute a REST call to get the Bearer Token and another to Get Resource Groups.

Azure Cli Download Mac

Install Postman

Install Postman, to execute the REST APIs.

Close Postman

For PC Only…

The next step only works if Postman is closed. Please close Postman now.

People have reported that you don't need to do this on Mac.

Azure Cli Download Mac High Sierra

Click 'Run in Postman'

Azure

Click this button:

This will open your browser and present you with two options. Select the best option for you under 'Open with…' On Windows select 'Open with…Postman for Windows'

Inspect Requests

You will notice that there is a new collection in Postman called 'Azure REST'. Take a few minutes to inspect the requests and get familiar with them.

Get AAD Token Request

Azure Cli Download Mac Download

This request will POST to https://login.microsoftonline.com/{{tenantId}}/oauth2/token with our Service Principal settings and then, in the 'Tests' will set a Postman Global Variable called bearerToken to the access_token in the response.

Get Resource Groups Request

This request will GET https://management.azure.com/subscriptions/{{subscriptionId}}/resourcegroups?api-version=2019-10-01 with an Authorization header set to the Bearer Token we just requested with ‘Get AAD Token'.

See https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups for latest api-version value

Set Environment Variables

When you clicked on the 'Run in Postman' button Postman also created an Environment for you called 'Azure REST'. You will now set your Service Principal settings in the Environment to be used in the requests.

  • Click on the gear icon in the upper right hand corner of Postman and select Manage Environments.
  • Click on the Azure REST Environment and you will see all the required settings.
  • Enter all your settings from the Service Principal we created earlier. Here's how they map:

Azure Cli Download Mac 10.10

az account show --query id

When you are done it will look like this with all the values filled in:

Make sure that the Azure REST Environment is selected in the Environment dropdown in the upper right hand corner of Postman.

We are now ready to execute the requests!

Execute Get AAD Token Request

First, we will execute the Get AAD Token request to get our Bearer Token and put it in a Postman global variable.

Azure Cli Download Mac

Note that the below configuration uses the default Service Principal configuration values. In a production application you are going to want to configure the Service Principal to be constrained to specific areas of your Azure resources. You can find more info on the configuration options in the Azure CLI Service Principal Documentation.

Get the Azure CLI

Install Azure Cli Mac

You have two options when executing Azure CLI commands:

Azure Cloud Shell

Go to Azure Cloud Shell

Local with Azure CLI

Install Azure CLI 2.0

Login

If a browser doesn't automatically open, go to http://aka.ms/devicelogin and enter the code show in the console.

Set Active Subscription

Create Service Principal

Copy this output to a temp location, you will need the values in a minute.

Service Principal Password Reset

You can execute the following command if you ever need to reset your Service Principal password.

You can read more about Service Principals here.

Postman Setup

We are now going to use Postman to execute a REST call to get the Bearer Token and another to Get Resource Groups.

Install Postman

Install Postman, to execute the REST APIs.

Close Postman

For PC Only…

The next step only works if Postman is closed. Please close Postman now.

People have reported that you don't need to do this on Mac.

Azure Cli Download Mac High Sierra

Click 'Run in Postman'

Click this button:

This will open your browser and present you with two options. Select the best option for you under 'Open with…' On Windows select 'Open with…Postman for Windows'

Inspect Requests

You will notice that there is a new collection in Postman called 'Azure REST'. Take a few minutes to inspect the requests and get familiar with them.

Get AAD Token Request

Azure Cli Download Mac Download

This request will POST to https://login.microsoftonline.com/{{tenantId}}/oauth2/token with our Service Principal settings and then, in the 'Tests' will set a Postman Global Variable called bearerToken to the access_token in the response.

Get Resource Groups Request

This request will GET https://management.azure.com/subscriptions/{{subscriptionId}}/resourcegroups?api-version=2019-10-01 with an Authorization header set to the Bearer Token we just requested with ‘Get AAD Token'.

See https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups for latest api-version value

Set Environment Variables

When you clicked on the 'Run in Postman' button Postman also created an Environment for you called 'Azure REST'. You will now set your Service Principal settings in the Environment to be used in the requests.

  • Click on the gear icon in the upper right hand corner of Postman and select Manage Environments.
  • Click on the Azure REST Environment and you will see all the required settings.
  • Enter all your settings from the Service Principal we created earlier. Here's how they map:

Azure Cli Download Mac 10.10

az account show --query id

When you are done it will look like this with all the values filled in:

Make sure that the Azure REST Environment is selected in the Environment dropdown in the upper right hand corner of Postman.

We are now ready to execute the requests!

Execute Get AAD Token Request

First, we will execute the Get AAD Token request to get our Bearer Token and put it in a Postman global variable.

  • Open the Get AAD Token request and click the Send button.

You will see the following output:

The access_token property is now stored a global variable, which was set in the 'Tests' tab.

Execute Get Resource Groups Request

We'll now execute any Azure REST API with that Bearer Token. Just as an exercise, we'll execute the Get Resource Groups request.

  • Open the Get Resource Groups request and click the Send button.

You will see the following output:

That's all there is to it. Now you can go an explore all of the Azure REST APIs and use this same method to generate the required Bearer Token Authorization header.

Please let me know if you run in to any issues.

Jon





broken image