Quickstart: Azure Blob Storage
This quickstart guide will walk you through the essential steps to get started with Azure Blob Storage using the Azure CLI.
What is Azure Blob Storage?
Azure Blob Storage is Microsoft's cloud object storage solution. Blob storage is optimized for storing massive amounts of unstructured data, such as text or binary data. Unstructured data includes things like images, audio, video, documents, and application data.
Key scenarios for using Blob Storage include:
- Serving images or documents directly to a browser.
- Storing files for distributed access.
- Streaming video and audio.
- Writing to log files.
- Storing data for backup and restore, disaster recovery, and archiving.
Prerequisites
- An Azure Subscription: If you don't have one, create a free account before you begin.
- Azure CLI: Install the Azure Command-Line Interface. You can find instructions for your operating system here.
Step 1: Sign in to Azure
Open your terminal or command prompt and sign in to your Azure account:
az login
Follow the instructions to authenticate your browser.
Step 2: Create a Resource Group
A resource group is a logical container into which Azure resources are deployed and managed. Create a new resource group for this quickstart:
az group create --name myResourceGroup --location eastus
Replace myResourceGroup with a unique name for your resource group and eastus with the desired Azure region.
Step 3: Create a Storage Account
Create a general-purpose v2 storage account. Storage account names must be globally unique, lowercase, and between 3 and 24 characters.
az storage account create --resource-group myResourceGroup --name mystorageaccountquickstart --sku Standard_LRS --kind StorageV2 --location eastus
Replace mystorageaccountquickstart with a unique name for your storage account.
Tip:
The --sku Standard_LRS option specifies Locally-Redundant Storage, which is a cost-effective option for data that is not mission-critical. For production workloads, consider other redundancy options like ZRS, GRS, or RA-GRS.
Step 4: Create a Container
Containers are used to organize blobs within a storage account. Create a blob container:
az storage container create --name mycontainer --account-name mystorageaccountquickstart --auth-mode login
Replace mycontainer with your desired container name and mystorageaccountquickstart with your storage account name.
Step 5: Upload a File
Now, let's upload a file to the container. First, create a sample text file named sample.txt in your current directory with some content.
Upload the file using the Azure CLI:
az storage blob upload --container-name mycontainer --name sample.txt --file sample.txt --account-name mystorageaccountquickstart --auth-mode login
Step 6: List Blobs
List the blobs in your container to verify the upload:
az storage blob list --container-name mycontainer --account-name mystorageaccountquickstart --auth-mode login --output table
Step 7: Download the File
Download the file from the container:
az storage blob download --container-name mycontainer --name sample.txt --file sample_downloaded.txt --account-name mystorageaccountquickstart --auth-mode login
A new file named sample_downloaded.txt will be created in your current directory. You can compare it with sample.txt to confirm the download.
Step 8: Clean up Resources
To avoid ongoing charges, delete the resource group you created. Deleting the resource group deletes all resources contained within it.
az group delete --name myResourceGroup --yes --no-wait
Next Steps:
Congratulations! You've completed the Azure Blob Storage quickstart. You can now explore more advanced features like: