Managing Cloud Storage from the Command Line
Contents
Managing Cloud Storage from the Command Line#
Overview
Teaching:
Exercises:
Questions:
How do I store data in the cloud?
Objectives:
Create a Storage Account
Create a bucket
Learn to copy data in/out of a bucket using the command line.
Clean up resources
Now that Drew understands how to create buckets using the web console and to use the Azure command line tools. Now Drew is going learn to manage blobs using the command line.
The first thing Drew needs to do before manipulating blobs is give himself the role “Storage Blob Data Contributor” in oder to interact with blobs.
az ad signed-in-user show --query objectId -o tsv | az role assignment create \
--role "Storage Blob Data Contributor" \
--assignee @- \
--scope "/subscriptions/<subscription>/resourceGroups/<resource group>/providers/Microsoft.Storage/storageAccounts/<storage account>"
az ad signed-in-user show --query objectId -o tsv | az role assignment create --role "Storage Blob Data Contributor" --assignee @- --scope "/subscriptions/$SUB/resourceGroups/$RG/providers/Microsoft.Storage/storageAccounts/$STGE_ACCT"
Create a blob and upload to blob storage#
Now we will upload a file from your local machine.
Create a file to upload
echo "Demo text" > demo_file.txt
Copy demo_file.txt to your blob.
az storage blob upload --account-name $STGE_ACCT --container-name $BLOB_CONT --name demo_file_upload.txt --file demo_file.txt --auth-mode login
Verify that the blob is there by listing the blobs in the container.
az storage blob list --account-name $STGE_ACCT --container-name $BLOB_CONT --output table --auth-mode login
Download the file we just uploaded.
az storage blob download --account-name $STGE_ACCT --container-name $BLOB_CONT --name demo_file_upload.txt --file demo_file_download.txt --auth-mode login
In Cloud Shell type the following command:
ls demo_file_download.txt
Clean up#
Clean up the resources in this lesson in the reverse order that we created them.
Delete a blob
az storage blob delete --account-name $STGE_ACCT --container-name $BLOB_CONT --name demo_file_upload.txt --auth-mode login
Clean up Storage Account#
Delete the Storage Account.
az storage account delete -n $STGE_ACCT -g $RG
Verify that the Storage Account has been deleted.
az storage account list | grep $STGE_ACCT