You can automate the deletion of blobs associated with deleted experiments using a script.
You can schedule this script to run periodically using Azure Functions, Azure Automation, or even a simple cron job on a virtual machine.
from azureml.core import Workspace
from azure.storage.blob import BlobServiceClient, ContainerClient
import os
# Load your Azure ML workspace
ws = Workspace.from_config()
# Get the default datastore (usually the blob storage account)
default_ds = ws.get_default_datastore()
# Connect to the blob storage account
blob_service_client = BlobServiceClient(account_url=default_ds.account_url, credential=default_ds.credential)
container_client = blob_service_client.get_container_client(default_ds.container_name)
# List all experiments
experiments = ws.experiments
# Iterate through experiments and delete blobs for deleted experiments
for exp in experiments:
if exp.archived: # Check if the experiment is deleted/archived
print(f"Deleting blobs for experiment: {exp.name}")
# List blobs in the experiment's folder
blobs = container_client.list_blobs(name_starts_with=f"experiments/{exp.name}/")
for blob in blobs:
print(f"Deleting blob: {blob.name}")
container_client.delete_blob(blob.name)
print("Blob cleanup completed.")