Store files in the cloud with Azure Blob Storage: create a storage account and containers, upload and download blobs, pick access tiers to cut costs, automate cleanup with lifecycle rules, and host a static website.
Azure stores files ("blobs") inside "containers," which live in a "storage account." Why three levels: the account is the billing/endpoint boundary (its name is globally unique), containers group blobs like folders, and blobs are the files themselves. It is Azure's equivalent of S3 buckets and objects.
Create a storage account (name: 3-24 lowercase letters/numbers, global-unique)
az storage account create \
--resource-group learn-rg \
--name learnstore7f3k \
--location eastus \
--sku Standard_LRSCreate a container inside it
az storage container create \
--account-name learnstore7f3k --name uploads --auth-mode loginOnce you have a container you can put files in and pull them out. Why --auth-mode login: it uses your signed-in identity (and RBAC) instead of an account key, which is the modern, safer way to authenticate the CLI.
Upload a file
az storage blob upload --account-name learnstore7f3k \
--container-name uploads --name photo.jpg \
--file ./photo.jpg --auth-mode loginList what's in the container
az storage blob list --account-name learnstore7f3k \
--container-name uploads --auth-mode login --output tableDownload it back
az storage blob download --account-name learnstore7f3k \
--container-name uploads --name photo.jpg \
--file ./downloaded.jpg --auth-mode loginNot all data is read equally. Tiers trade retrieval cost for storage cost: Hot (frequent access, default), Cool (infrequent, cheaper to store), Cold, and Archive (rarely read, cheapest, but takes hours to rehydrate). Why: moving old data to Cool or Archive can cut the bill dramatically.
Upload straight into the Cool tier
az storage blob upload --account-name learnstore7f3k \
--container-name uploads --name old-report.pdf \
--file ./old-report.pdf --tier Cool --auth-mode loginMove an existing blob to the Archive tier
az storage blob set-tier --account-name learnstore7f3k \
--container-name uploads --name old-report.pdf \
--tier Archive --auth-mode loginA lifecycle policy transitions or deletes blobs automatically as they age. Why: instead of cleaning up by hand, you say "cool after 30 days, archive after 90, delete after a year" once, and Azure enforces it forever.
Save this as lifecycle.json
{
"rules": [{
"name": "archive-then-delete",
"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 learnstore7f3k --resource-group learn-rg \
--policy @lifecycle.jsonBlob versioning keeps a copy whenever a blob is overwritten; soft delete keeps deleted blobs for a retention window. Why: together they let you roll back an accidental overwrite or recover a deleted file — a safety net you turn on at the account level.
Enable versioning and 7-day soft delete on the account
az storage account blob-service-properties update \
--account-name learnstore7f3k --resource-group learn-rg \
--enable-versioning true \
--enable-delete-retention true --delete-retention-days 7A storage account can serve a folder of HTML/CSS/JS straight to browsers — no server needed. Why: it is the cheapest way to host a static site or single-page app. For HTTPS on a custom domain you put Front Door or a CDN (next lessons) in front.
Turn on static website hosting with an index and 404 page
az storage blob service-properties update \
--account-name learnstore7f3k --auth-mode login \
--static-website --index-document index.html \
--404-document error.htmlUpload the site into the special $web container
az storage blob upload-batch --account-name learnstore7f3k \
--source ./dist --destination '$web' --auth-mode loginThe site URL is shown by:
az storage account show --name learnstore7f3k --resource-group learn-rg \
--query 'primaryEndpoints.web' --output tsv