We love the CLI ๐. Cheatsheet with the most common Microsoft Azure CLI commands with examples.
Each section covers one specific set of resources you can manage with your CLI. Per each section you will find the following information:
- Title: The resources set name that you can manage with the CLI
- Command: Remember this one. It's the basic thing to start. For instance,
az group
is all about manage resource groups. - Basic actions: Basic actions you can do in the command. Tip: mentally join command and basic action and you will be at half way to use the CLI to manage the resource.
- Examples: Set of examples using that command and the basic actions. First, it is described in human expression what you want to perform and the line after, the command that perform the action. Try to link the way of thinking and the sequence of the command and you will never forget a command again.
Note: In the examples is assumed that all the actions are based on your subscription account.
$ az group
Command | Description |
---|---|
create | Create a new resource group. |
delete | Delete a resource group. |
exists | Check if a resource group exists. |
list | List resource groups. |
show | Gets a resource group.. |
- Create a resource group called
playground
innortheurope
$ az group create -l "northeurope" -n "playground"
- Does it my resource group called
playground
exists?
$ az group exists -n "playground"
- Give me a list with all my resource group
$ az group list
- Show me the resouce group called
playground
$ az group show -n "playground"
- Delete the group
playground
and do not give me confirmation
$ az group delete -n "playground" -y
$ az storage account
Command | Description |
---|---|
create | Create a storage account. |
delete | Delete a storage account. |
check-name | Check if a resource group exists. |
list | List resource groups. |
show | Gets a resource group.. |
- Create a storage account group called
mystorageaccount
in the resource group calledplayground
, in the locationnortheurope
and with store-keeping unitStandard_LRS
$ az storage account create -n "mystorageaccount" -g "playground" -l "northeurope" --sku Standard_LRS
$ az batch account
Command | Description |
---|---|
create | Create a new batch account. |
login | Specify which batch account the CLI should wotj with. |
$ az batch pool
Command | Description |
---|---|
create | Create a new pool. |
show | Show me the information of certain pool |
delete | Delete a pool |
$ az batch job
Command | Description |
---|---|
create | Create a new pool. |
show | Show me the information of certain pool |
$ az batch task
Command | Description |
---|---|
create | Create a new task. |
show | Show me the information of certain pool |
file list | List all the files created for that task |
file download | Download files created for that task |
- Create a batch account group called
mybatchaccount
in the storage account calledmystorageaccount
in the resource group calledplayground
and in the locationnortheurope
.
$ az batch account create -n "mybatchaccount" --storage-account "mystorageaccount" -g "playground" -l "northeurope"
- Tell to CLI that I am working with the batch account called
mybatchaccount
in the resource group calledplayground
. For that, I am sharing the authorization keys with you.
$ az batch account login -n "mybatchaccount" -g "playground" --shared-key-auth
- Create a pool with the id
myfirstpool
with the virtual machine sizeStandard_A1_V2
with 2 dedicated nodes, usingcanonical:ubuntuserver:16.04-LTS
as OS and with node agentbatch.node.ubuntu 16.04
$ az batch pool create `
--id "myfirstpool" `
--vm-size Standard_A1_v2 `
--target-dedicated-nodes 2 `
--image `
canonical:ubuntuserver:16.04-LTS `
--node-agent-sku-id `
"batch.node.ubuntu 16.04"
- Show me state of creation of my pool with id
myfirstpool
$ az batch pool show --pool-id $poolName --query "allocationState"
- Create a job with the id
myjob
in my pool with idmyfirstpool
$ az batch job create --id myjob --pool-id "myfirstpool"
- Create a task with id
myfirsttask
in the job with the idmyjob
and the job consist of execute the following command line:/bin/bash -c 'printenv | grep AZ_BATCH; sleep 90s'
$ az batch task create `
--task-id myfirsttask `
--job-id myjob `
--command-line "/bin/bash -c 'printenv | grep AZ_BATCH; sleep 90s'"
- Show me all the information of my task with id
myfirsttask
of my job with idmyjob
$ az batch task show --task-id myfirsttask --job-id myjob
- I want to list the files resulting of my task with id
myfirsttask
of my job with idmyjob
. Show me the results in table format.
$ az batch task file list --job-id myjob --task-id myfirsttask --output table
- Download the file
stdout.txt
created in my task with idmyfirsttask
of my job with idmyjob
. The destination in my local computer will be./stdout.txt
$ az batch task file download `
--job-id myjob `
--task-id myfirsttask `
--file-path stdout.txt `
--destination ./stdout0.txt
Command | Description |
---|---|
create | Create a new ask kluster. |
$ az aks
- Create an AKS cluster called
mykubercluster
in the resource group calledplayground
with one node (VM) and create in my local machine the ssh keys to access to it.
$ az aks create -n "mykubercluster" -g "playground" --node-count 1 --generate-ssh-keys
$ az webapp
Command | Description |
---|---|
create | Create a web app resource. |
deployment | Show me the information of certain pool |
config | List all the files created for that task |
- Create a web app group called
mywebapp
in the resource group calledplayground
and with the app service plan created before callemyfreeserviceplan
.
$ az webapp create -n "mywebapp" -g "playground" --plan "myfreeserviceplan"
- Deploy to my web app called
mywebapp
in the resource group calledplayground
the code that have in githubhttps://github.com/cesiztel/azure-cli-hero
based on the master branch and I will manually triggered.
$ az webapp deployment source config `
-n "mywebapp" `
-g "playground" `
--repo-url "https://github.com/cesiztel/azure-cli-hero" `
--branch "master" `
--manual-integration
- Sync all the code configure with my git repo and master branch for the web app called
mywebapp
in the resource group called `playground
$ az webapp deployment source sync -n "mywebapp" -g "playground"