Ask Your Question
2

How can key vault be utilized to access Azure blob storage in Databricks?

asked 2023-01-29 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-07-22 17:00:00 +0000

woof gravatar image

Key Vault can be utilized to access Azure blob storage in Databricks by following these steps:

  1. Create a Key Vault in Azure and store the storage account key as a secret in the Key Vault.
  2. Add the Databricks app to the Key Vault's Access Policies in Azure.
  3. In your Databricks notebook, use the Azure Blob Storage Connector to link to the Azure Blob storage account.
  4. In the Databricks notebook, use the dbutils.secrets.get command to retrieve the storage account key from the Key Vault.
  5. Use the retrieved storage account key to authenticate the Blob Storage Connector and access the Blob storage account.

Here's an example code snippet that shows how to utilize Key Vault to access Azure blob storage in Databricks:

# Import the Azure Blob Storage Connector
from azure.storage.blob import BlobServiceClient

# Retrieve the storage account key from Key Vault
storage_account_key = dbutils.secrets.get(scope="<Key Vault Scope>", key="<Storage Account Key Secret Name>")

# Connect to Blob Storage using the storage account name and retrieved key
blob_service_client = BlobServiceClient(account_url="https://<Storage Account Name>.blob.core.windows.net", credential=storage_account_key)

# List the containers in the Blob Storage account
containers = blob_service_client.list_containers()
for container in containers:
    print(container.name)

Note: Replace <Key Vault Scope>, <Storage Account Key Secret Name>, and <Storage Account Name> with your specific values.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-29 11:00:00 +0000

Seen: 14 times

Last updated: Jul 22 '21