Managing Blob Containers on Azure VM
Requirements
The Nautilus DevOps team needs to set up an Azure Virtual Machine (VM) to interact with an Azure Blob Storage container for storing and retrieving data. The team must create a private storage account, configure Blob Storage, and test the functionality.
Task
- Azure Virtual Machine Setup:
- The VM named
xfusion-vmalready exists in the East US region.
- Create a Private Storage Account and Blob Container:
- Create a storage account named
xfusionstor26890in the East US region with Locally-redundant storage (LRS). - Create a private Blob container named
xfusion-container26890.
- Retrieve Storage Account Key:
- Get the storage account's access key to configure access for the application.
- Create a Test File:
- SSH into the VM and create a file named
testfile.txtin the/home/azureuserdirectory with content: "this is a test file".
- Upload the File to Blob Storage:
-
Upload the
testfile.txtfile to the Blob containerxfusion-container26890using the Azure CLI command:az storage blob upload --account-name xfusionstor26890 --account-key <access-key> --container-name xfusion-container26890 --name testfile.txt --file /home/azureuser/testfile.txt
Note
This workflow uses account key-based auth because it matches the exact task validation behavior.
Prerequisites
- Azure CLI installed and logged in.
- Existing VM
xfusion-vmwith SSH access. - Resource group available in East US.
Steps
RG=$(az group list --query "[?contains(name, 'kml')].name" --output tsv)
STORAGE_ACCOUNT="xfusionstor26890"
CONTAINER_NAME="xfusion-container26890"
LOCATION="eastus"
VM_NAME="xfusion-vm"
VM_USER="azureuser"
az storage account create \
--name "$STORAGE_ACCOUNT" \
--resource-group "$RG" \
--location "$LOCATION" \
--sku Standard_LRS \
--kind StorageV2
az storage container create \
--name "$CONTAINER_NAME" \
--account-name "$STORAGE_ACCOUNT" \
--public-access off
KEY=$(az storage account keys list \
--resource-group "$RG" \
--account-name "$STORAGE_ACCOUNT" \
--query "[0].value" -o tsv)
PUBLIC_IP=$(az vm show --show-details \
--name "$VM_NAME" \
--resource-group "$RG" \
--query publicIps -o tsv)
echo "ssh ${VM_USER}@${PUBLIC_IP}"
echo "echo 'this is a test file' > /home/azureuser/testfile.txt"
echo "az storage blob upload --account-name ${STORAGE_ACCOUNT} --account-key <key> --container-name ${CONTAINER_NAME} --name testfile.txt --file /home/azureuser/testfile.txt"
Verification
- Verify storage account exists:
az storage account show --name "$STORAGE_ACCOUNT" --resource-group "$RG" --query name -o tsv
- Verify container exists:
az storage container show --name "$CONTAINER_NAME" --account-name "$STORAGE_ACCOUNT" --account-key "$KEY" --query name -o tsv
- Verify blob upload:
az storage blob list --account-name "$STORAGE_ACCOUNT" --account-key "$KEY" --container-name "$CONTAINER_NAME" --query "[?name=='testfile.txt'].name" -o tsv