Cloud Computing on Azure - Assignment 3: Working with Azure Blob Storage
Objective:
This assignement will guide you through Azure Storage service. You will manipulate Blob objects using the Azure portal, the CLI and the Python SDK.
Part 1: Managing Files in Blob
Storage using Azure Portal
-
Task:
Create a new Azure Blob Storage Account and configure it for storing unstructured data like
files, images, and documents.
-
Instructions:
- In the Azure portal, navigate to Storage Accounts and click Create.
- Set the following:
- Resource Group: Use the existing resource group (
CloudBasics_RG
).
- Storage Account Name: Choose a unique name (e.g.,
myblobstorage01
).
- Region: Same as your other resources.
- Performance: Choose Standard.
- Replication: Choose Locally Redundant Storage (LRS).
- Once the account is created, navigate to the Containers section in Blob Services and create
a new container, use a unique name (e.g.,
2024-10-10-container-1
).
- Once the container is created, create a file locally using
touch file.txt
in your
terminal/using you laptop GUI, fill it with whatever you prefer and upload it to the blob storage via the
portal.
- Questions:
- What's a Blob?
- What's the access tier of the file you just uploaded?
- What's the difference between all access tiers?
Part 2: Managing Files in Blob
Storage using the CLI
-
Task:
Upload files to Azure Blob Storage using the Azure portal and Azure CLI.
-
Instructions: All the following should be done using the CLI.
- Create a new container in the storage account you created with the portal in Part 1. Name the container as
you like (e.g.
2024-10-10-container-2
).
- List all the containers in your storage account in a table. How many containers do you see?
- Download the file you uploaded to the storage in Part 1 in a file named
downloaded_file.txt
.
- Next, upload
downloaded_file
to file.txt
to the new container. What's the
output of the command?
- Now, upload all files of the archive you can find here to the new container withing a directory named
archive
. What's the output of the command?
- Verify the upload by listing the contents of the container (
2024-10-10-container-2
).
- Copy the previous container to a new one (
2024-10-10-container-3
) using the CLI. All objects inside the container should be copied.
- Delete the container created in Part 1 (
2024-10-10-container-1
).
-
Documentation: az storage container and
az storage blob.
Part 3: Managing Files in Blob using Python SDK
-
Task:
Upload and download files to storage account using Python SDK.
-
Instructions:
- Create a virtual environment using:
python -m venv .venv
Then activate your venv using:
source .venv/bin/activate
- Install the Azure Identity client library for Python:
pip install azure-identity
- Install the Azure Storage Blob client library for Python:
pip install azure-storage-blob
- Create a Python script to authenticate into your Azure account and connect to your blob storage account:
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
# Acquire a credential object
credential = DefaultAzureCredential()
blob_service_client = BlobServiceClient(account_url="https://my_account_name.blob.core.windows.net", credential=credential)
- Add to your script the ability to download a blob:
download_file_path = "downloaded_from_blob.txt"
with open(download_file_path, "wb") as download_file:
download_file.write(blob_client.download_blob().readall())
print(f"Blob {blob_name} downloaded to {download_file_path}")
- Run the script to download the files you uploaded in Part 2 to container (
2024-10-10-container-2
).
- Update your script to create a new container (
2024-10-10-container-4
) if it does not exist.
- Update your script to upload files to a given blob container, then re-upload all the files of the archive to (
2024-10-10-container-4
)
- Delete all containers you created in this assignement using Python (
2024-10-10-container-2
, 2024-10-10-container-3
, 2024-10-10-container-4
).
- What's the difference between a SDK and a CLI?