I am trying to access a blob storage like this and it works
from azure.storage.blob import ContainerClient
storage_account_name ='storage_account_name'
storage_container_name = 'storage_container_name'
sas_token = 'sv=<>&si=<>&sr=<>&sig=<>'
account_url = "https://"+storage_account_name+".blob.core.windows/"+storage_container_name+"?"+sas_token
container_client = ContainerClient.from_container_url(container_url=account_url)
blobs = container_client.list_blobs()
for blob in blobs:
print(blob)
But if I get the secret through dbutils and try to pass it through, it does not.
from azure.storage.blob import ContainerClient
storage_account_name ='storage_account_name'
storage_container_name = 'storage_container_name'
sas_token = dbutils.secrets.get(scope=secret_scope,key='some_key')
account_url = "https://"+storage_account_name+".blob.core.windows/"+storage_container_name+"?"+sas_token
container_client = ContainerClient.from_container_url(container_url=account_url)
blobs = container_client.list_blobs()
for blob in blobs:
print(blob)
Is it possible to keep on using dbutils and make it work
I am trying to access a blob storage like this and it works
from azure.storage.blob import ContainerClient
storage_account_name ='storage_account_name'
storage_container_name = 'storage_container_name'
sas_token = 'sv=<>&si=<>&sr=<>&sig=<>'
account_url = "https://"+storage_account_name+".blob.core.windows/"+storage_container_name+"?"+sas_token
container_client = ContainerClient.from_container_url(container_url=account_url)
blobs = container_client.list_blobs()
for blob in blobs:
print(blob)
But if I get the secret through dbutils and try to pass it through, it does not.
from azure.storage.blob import ContainerClient
storage_account_name ='storage_account_name'
storage_container_name = 'storage_container_name'
sas_token = dbutils.secrets.get(scope=secret_scope,key='some_key')
account_url = "https://"+storage_account_name+".blob.core.windows/"+storage_container_name+"?"+sas_token
container_client = ContainerClient.from_container_url(container_url=account_url)
blobs = container_client.list_blobs()
for blob in blobs:
print(blob)
Is it possible to keep on using dbutils and make it work
Share Improve this question asked Mar 31 at 16:32 smpa01smpa01 4,3463 gold badges18 silver badges30 bronze badges 3 |1 Answer
Reset to default 1To fetch the container files using secret scope dbutils please follow the below steps: You should have Premium Teir Subscription in Azure Databricks to create Secret Scope.
Create Secret scope and add secrets :
databricks secret create-scope scopename
--create secret scope
databricks secrets list-scopes
--check the scope is created
databricks secrets put-secret scopename keyname
--create secret inside scope and enter the value of key (copied from storage account SAS key) to get it createddatabricks secrets list-secrets scopename
--to check if the secret is created or notNow in Databricks workspace run the following :
dbutils.secrets.get(scope="scopename", key="keyname")
Output: '[REDACTED]' is expected because Databricks hides secret values when printed to maintain security.
Now the final code : It fetches the files from the container
Please refer to Microsoft Documents for more details:
Azure Databricks Secrets Creation
Azure Storage Blob Library
dbutils.secrets.get(scope='secret_scope_name',key='some_key')
. You can also usedbutils.secrets.list(secret_scope)
to verify that you can see all the key names available in that secret scope – EricL Commented Mar 31 at 21:12