Search code examples
azureazure-blob-storageazure-storageazure-synapseazure-data-lake-gen2

Access ADLS Gen2 objects based on tier (Hot, Cool)


I need to move objects from Hot tier to Cool tier, which I was able to achieve using "Life Cycle Management" by creating some rules.

Now I need to read all the object names which now has been moved to Cool tier using a Synapse notebook or by any other means.

How can this be achieved?


Solution

  • You can follow the procedure below to list the objects in an ADLS account:

    Go to Shared access signature and generate a connection string with the following permissions:

    enter image description here

    Copy the connection string as shown below:

    enter image description here

    Use the following code to list the objects in a Synapse notebook:

    from azure.storage.blob import BlobServiceClient
    
    connection_string = "<connectionString>"
    container_name = "<container>"
    
    blob_service_client = BlobServiceClient.from_connection_string(connection_string)
    container_client = blob_service_client.get_container_client(container_name)
    
    blob_list = container_client.list_blobs()
    for blob in blob_list:
      if blob.blob_tier == "Cool":
        print(blob.name)
    

    This will list the objects as shown below:

    enter image description here