How to use the command 'az storage' (with examples)
Azure Cloud Storage is a feature offered by Microsoft Azure that allows users to store and manage large amounts of unstructured data like documents, images, videos, etc. The az storage
command, which is part of the Azure CLI (also known as az
), enables users to manage their Azure Cloud Storage resources.
Use case 1: Create a storage account
Code:
az storage account create --resource-group group_name --name account_name -l location --sku account_sku
Motivation: Creating a storage account is the first step to start using Azure Cloud Storage. This command allows you to create a new storage account in your Azure subscription.
Explanation:
--resource-group group_name
: Specifies the name of the resource group to which the storage account belongs.--name account_name
: Specifies the name of the storage account.-l location
: Specifies the Azure region where the storage account will be created.--sku account_sku
: Specifies the storage account’s SKU (Standard_LRS, Standard_ZRS, Standard_GRS, etc.).
Example output:
{
"accessTier": "Hot",
"accessTierChangeTime": null,
"azureFilesIdentityBasedAuthentication": {
"directoryServiceOptions": null,
"enabled": false
},
"creationTime": "2022-01-01T00:00:00+00:00",
"customDomain": null,
"enableHttpsTrafficOnly": true,
...
}
Use case 2: List all storage accounts in a resource group
Code:
az storage account list --resource-group group_name
Motivation: If you have multiple storage accounts in a resource group, this command allows you to list all the storage accounts for easy management.
Explanation:
--resource-group group_name
: Specifies the name of the resource group to which the storage accounts belong.
Example output:
[
{
"name": "account1",
"location": "eastus",
"sku": {
"name": "Standard_LRS"
},
...
},
{
"name": "account2",
"location": "westus",
"sku": {
"name": "Standard_GRS"
},
...
}
]
Use case 3: List the access keys for a storage account
Code:
az storage account keys list --resource-group group_name --name account_name
Motivation: Access keys are used to authenticate requests made to a storage account. This command allows you to retrieve the access keys for a specific storage account.
Explanation:
--resource-group group_name
: Specifies the name of the resource group to which the storage account belongs.--name account_name
: Specifies the name of the storage account.
Example output:
[
{
"keyName": "key1",
"permissions": "Full",
"value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"keyName": "key2",
"permissions": "Full",
"value": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
}
]
Use case 4: Delete a storage account
Code:
az storage account delete --resource-group group_name --name account_name
Motivation: If you no longer need a storage account, this command allows you to delete it to free up resources and avoid unnecessary costs.
Explanation:
--resource-group group_name
: Specifies the name of the resource group to which the storage account belongs.--name account_name
: Specifies the name of the storage account.
Example output:
{
"deletedTime": "2022-01-01T00:00:00+00:00",
"status": "Succeeded"
}
Use case 5: Update the minimum tls version setting for a storage account
Code:
az storage account update --min-tls-version TLS1_0|TLS1_1|TLS1_2 --resource-group group_name --name account_name
Motivation: This command allows you to update the minimum TLS (Transport Layer Security) version setting for a storage account. TLS is a cryptographic protocol used to secure network communications, and updating the minimum TLS version helps to keep your storage account more secure.
Explanation:
--min-tls-version TLS1_0|TLS1_1|TLS1_2
: Specifies the minimum TLS version to be used (TLS1_0, TLS1_1, or TLS1_2).--resource-group group_name
: Specifies the name of the resource group to which the storage account belongs.--name account_name
: Specifies the name of the storage account.
Example output:
{
"minTlsVersion": "TLS1_2",
...
}
Conclusion:
The az storage
command is a powerful tool for managing Azure Cloud Storage resources. With the provided examples, you can create a storage account, list storage accounts in a resource group, retrieve access keys, delete a storage account, and update TLS settings. These commands enable efficient management and control over your Azure Cloud Storage resources.