Automating Azure Blob Storage with Bash and Azure CLI: A Real-World Use Case
In modern cloud-native development, automation is no longer a luxury—it's a necessity. Whether you're deploying infrastructure, provisioning storage, or managing CI/CD pipelines, scripting cloud interactions ensures consistency, speed, and scalability.
In this blog post, we'll walk through a real-world scenario that leverages Azure CLI and Bash scripting to create a resource group, a storage account, multiple blob containers, and upload files—all with a few lines of code.
Real-World Use Case: Multi-Team Container Initialization
Imagine a scenario in a software engineering company where three different teams—Amin, Oscar, and Felipe—need isolated blob containers to store logs, deployment artifacts, or backups. Instead of doing this manually through the Azure Portal, we’ll script it!
Script Overview
Here’s our automation script using Azure CLI in a bash shell:
#!/bin/bash
# Step 1: Create a resource group
az group create --name grupoAlmacenamiento --location "eastus2"
# Step 2: Create a storage account
az storage account create --name almacenamientoap --resource-group grupoAlmacenamiento --location eastus2 --sku Standard_LRS
# Step 3: Fetch the storage account key
AZURE_STORAGE_KEY=$(az storage account keys list --account-name almacenamientoap --resource-group grupoAlmacenamiento --query "[0].value" --output tsv)
# Step 4: Create multiple containers for separate teams
az storage container create --name amin --account-name almacenamientoap --account-key $AZURE_STORAGE_KEY
az storage container create --name oscar --account-name almacenamientoap --account-key $AZURE_STORAGE_KEY
az storage container create --name felipe --account-name almacenamientoap --account-key $AZURE_STORAGE_KEY
# Step 5: Upload a script to one of the containers
az storage blob upload --container-name amin --file ./comandos.sh --name comandos.sh --account-name almacenamientoap
Why This Matters
- Consistency: Every environment starts the same way.
- Efficiency: Saves hours compared to point-and-click workflows.
- Security: Limits the exposure to manual misconfigurations.
- Repeatability: This script can be reused across projects and pipelines.
Key Azure Concepts Demonstrated
Concept | Purpose |
---|---|
az group create |
Organize resources for lifecycle and access control |
az storage account create |
Provision blob/file/table/queue storage in Azure |
az storage container create |
Logical divisions within the storage account |
az storage blob upload |
Upload content into a specified container |
az storage account keys list |
Retrieve access keys securely to interact with storage |
Extend the Automation
Want to take it further?
- Integrate with CI/CD (GitHub Actions, Azure DevOps)
- Use Azure Key Vault instead of inline keys
- Add
az group delete
at the end to clean up for test environments - Use container metadata for lifecycle tagging
Security Consideration
Using --account-key
in scripts is suitable for quick tasks but not recommended for production. Use Azure AD-based RBAC, SAS tokens, or managed identities for better security.
Final Thoughts
With just a few commands, we automated the creation of a scalable and logically organized Azure Blob Storage architecture. This approach not only reduces manual effort but aligns with DevOps best practices of automation, security, and scalability.
Azure CLI + Bash = Cloud Productivity Superpowers ⚡
✍️ Written by: Cristian Sifuentes – Full-stack dev crafting scalable apps with [NET - Azure], [Angular - React], Git, SQL & extensions. Clean code, dark themes, atomic commits
Top comments (0)