Azure Cheatsheet
Blob Storage
Use this Azure reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Create a Storage Account
# Create storage account (globally unique name, lowercase/digits only) az storage account create \ --name mystorageacct \ --resource-group myRG \ --location eastus \ --sku Standard_LRS \ --kind StorageV2 \ --access-tier Hot # Show connection string az storage account show-connection-string \ --name mystorageacct -g myRG -o tsv # Show account keys az storage account keys list --account-name mystorageacct -g myRG -o table
SKU Options
| SKU | Replication |
|---|---|
Standard_LRS | Locally redundant (3 copies, 1 datacenter) |
Standard_ZRS | Zone-redundant (3 zones, same region) |
Standard_GRS | Geo-redundant (LRS + async copy to paired region) |
Standard_RAGRS | GRS + read access to secondary |
Premium_LRS | Premium SSD (block blobs / page blobs) |
Containers
# Create a container az storage container create \ --name mycontainer \ --account-name mystorageacct \ --public-access off # off | blob | container # List containers az storage container list --account-name mystorageacct -o table # Delete a container az storage container delete --name mycontainer --account-name mystorageacct # Set public access level az storage container set-permission \ --name mycontainer \ --account-name mystorageacct \ --public-access blob # individual blobs readable
Upload / Download Blobs
# Upload a file az storage blob upload \ --account-name mystorageacct \ --container-name mycontainer \ --name myfile.txt \ --file ./myfile.txt # Upload with content type az storage blob upload \ --account-name mystorageacct \ --container-name mycontainer \ --name image.png \ --file ./image.png \ --content-type image/png # Upload entire directory (recursive) az storage blob upload-batch \ --account-name mystorageacct \ --destination mycontainer \ --source ./dist/ # Download a blob az storage blob download \ --account-name mystorageacct \ --container-name mycontainer \ --name myfile.txt \ --file ./downloaded.txt # Download entire container az storage blob download-batch \ --account-name mystorageacct \ --source mycontainer \ --destination ./local-dir/
List & Manage Blobs
| Command | What it does |
|---|---|
az storage blob list -c <container> --account-name <acct> -o table | List blobs |
az storage blob show -c <c> -n <blob> --account-name <acct> | Show metadata |
az storage blob delete -c <c> -n <blob> --account-name <acct> | Delete blob |
az storage blob copy start --source-uri <url> --destination-blob <name> ... | Server-side copy |
az storage blob set-tier -c <c> -n <blob> --tier Archive --account-name <acct> | Change access tier |
# List blobs with prefix filter az storage blob list \ --account-name mystorageacct \ --container-name mycontainer \ --prefix "logs/2024/" \ -o table
SAS Tokens
# Generate account-level SAS (all services) az storage account generate-sas \ --account-name mystorageacct \ --permissions acdlrw \ --services b \ --resource-types co \ --expiry 2025-01-01 \ -o tsv # Generate blob-level SAS URL az storage blob generate-sas \ --account-name mystorageacct \ --container-name mycontainer \ --name myfile.txt \ --permissions r \ --expiry 2025-01-01 \ --full-uri \ -o tsv # Generate container SAS az storage container generate-sas \ --account-name mystorageacct \ --name mycontainer \ --permissions racwl \ --expiry 2025-01-01 \ -o tsv
Static Website Hosting
# Enable static website az storage blob service-properties update \ --account-name mystorageacct \ --static-website \ --index-document index.html \ --404-document 404.html # Get the website URL az storage account show \ --name mystorageacct -g myRG \ --query "primaryEndpoints.web" -o tsv # Upload built site az storage blob upload-batch \ --account-name mystorageacct \ --destination '$web' \ --source ./dist/ \ --overwrite
Lifecycle Management
# Create a lifecycle policy (JSON file)
cat lifecycle-policy.json{
"rules": [
{
"name": "move-old-blobs",
"enabled": true,
"type": "Lifecycle",
"definition": {
"filters": { "blobTypes": ["blockBlob"], "prefixMatch": ["logs/"] },
"actions": {
"baseBlob": {
"tierToCool": { "daysAfterModificationGreaterThan": 30 },
"tierToArchive": { "daysAfterModificationGreaterThan": 90 },
"delete": { "daysAfterModificationGreaterThan": 365 }
}
}
}
}
]
}az storage account management-policy create \ --account-name mystorageacct -g myRG \ --policy @lifecycle-policy.json
azcopy (High-Performance Transfers)
# Download azcopy # https://aka.ms/downloadazcopy-v10-linux azcopy login # interactive login # Copy local → blob azcopy copy './data/*' 'https://mystorageacct.blob.core.windows.net/mycontainer/' # Copy blob → blob (cross-account) azcopy copy \ 'https://src.blob.core.windows.net/c/file?<SAS>' \ 'https://dst.blob.core.windows.net/c/file?<SAS>' # Sync (like rsync — skips unchanged) azcopy sync './data/' 'https://mystorageacct.blob.core.windows.net/mycontainer/' # Benchmark upload speed azcopy benchmark 'https://mystorageacct.blob.core.windows.net/mycontainer/'