Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run Azure Cli Script using my local Azure Cli installation

First off I feel crazy asking this, sorry if this is a really stupid question. It must be obvious as I have searched everywhere and cannot find an answer!

How I am supposed to run this Azure script to create an Azure Function App? https://docs.microsoft.com/en-us/azure/azure-functions/scripts/functions-cli-create-serverless

#!/bin/bash

# Function app and storage account names must be unique.
storageName=mystorageaccount$RANDOM
functionAppName=myserverlessfunc$RANDOM

# Create a resource group.
az group create --name myResourceGroup --location westeurope

# Create an Azure storage account in the resource group.
az storage account create \
  --name $storageName \
  --location westeurope \
  --resource-group myResourceGroup \
  --sku Standard_LRS

# Create a serverless function app in the resource group.
az functionapp create \
  --name $functionAppName \
  --storage-account $storageName \
  --consumption-plan-location westeurope \
  --resource-group myResourceGroup

Clean up deployment

The page gives an example of how to run it using the console in the portal and the page also suggests I can run it locally if install the Azure CLI which I have. I need to run it from my local machine so that it can be automated with parameters.

However this page tells me nothing.

What should the extension of this file be ? .sh? What command do I use to call the script from my cli?

I have tried just typing the file name saved as .sh

e.g I have az --help and I can't see anything there either.

like image 468
Lenny D Avatar asked Aug 07 '18 12:08

Lenny D


People also ask

Can you run PowerShell script from Azure CLI?

Azure CLI can be run in both PowerShell and CMD, but PowerShell gives you more tab-completion features.

How do I open a local Azure command-line?

How to sign into the Azure CLI. Before using any Azure CLI commands with a local install, you need to sign in with az login. Run the login command. If the CLI can open your default browser, it will initiate authorization code flow and open the default browser to load an Azure sign-in page.

What do you need to install on your machine to let you execute Azure CLI commands locally?

Installing with PowerShell and MSI Installer If you like the command-line or need to automate installing the Azure CLI on Windows, you can also do so with PowerShell. To install the Azure CLI with PowerShell: Open Windows PowerShell as administrator.


1 Answers

I just tested this on my Mac.

Copy the script into a file with the .sh extension. I used test.sh.

Make sure you are logged into your local instance of Azure CLI.

Then just run: . /<path>/test.sh

like image 111
Travis Prescott Avatar answered Sep 23 '22 15:09

Travis Prescott