The Azure CLI can be used to perform many different operations for working with Azure Blob Storage.
This includes creating containers, listing containers, uploading blobs, listing blobs in a container, downloading blobs, deleting blobs and deleting containers.
In this tutorial, we will go over the Azure CLI commands for interacting with Azure Blob Storage.
Granting the Storage Blob Data Contributor Role to the signed in user
Next we will grant the Storage Blob Data Contributor Role to the signed in user enabling us to write blobs to the containers within the Azure Storage Account.
Note you will need to replace the <subscription-id>, <resource-group-name>, and <storage-account-name> with your own values
1
az ad signed-in-user show --query id -o tsv | az role assignment create --role "Storage Blob Data Contributor" --assignee "@-" --scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>"
You can check in the Azure Portal that this has been signed correctly under My Permissions.
Note that role changes can take up to 10 minutes to take effect.
Interacting with a Storage Account via the Azure CLI
Create a container in a storage account
1
az storage container create --account-name cloudengineerskillssa -n mystoragecontainer --auth-mode login
List all containers in a storage account
1
az storage container list --account-name cloudengineerskillssa --auth-mode login