Skip to content

Instantly share code, notes, and snippets.

@joanteixi
Created August 8, 2022 06:59
Show Gist options
  • Save joanteixi/d9cba6e8ffad57c24b3af531e34801fe to your computer and use it in GitHub Desktop.
Save joanteixi/d9cba6e8ffad57c24b3af531e34801fe to your computer and use it in GitHub Desktop.
Databricks mount Azure Storage with pyspark version
def mountContainer(appId, secret, tenantId, storageName, containerName, mountPoint):
configs = {"fs.azure.account.auth.type": "OAuth",
"fs.azure.account.oauth.provider.type": "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider",
"fs.azure.account.oauth2.client.id": appId,
"fs.azure.account.oauth2.client.secret": secret,
"fs.azure.account.oauth2.client.endpoint": f"https://login.microsoftonline.com/{tenantId}/oauth2/token"}
# Optionally, you can add <directory-name> to the source URI of your mount point.
dbutils.fs.mount(
source = f"abfss://{containerName}@{storageName}.dfs.core.windows.net/",
mount_point = f"/mnt/{mountPoint}",
extra_configs = configs)
appId = 'appidValue'
secret = 'secretValue'
tenantId = 'TenantId'
storageName = 'STORAGE_NAME_INSTANCE'
containerName= 'data'
mountPoint = 'data'
try:
dbutils.fs.unmount(f'/mnt/{mountPoint}')
except:
print('Directory not mounted')
mountContainer(appId, secret, tenantId, storageName, containerName, mountPoint)
print(f'Directory {mountPoint} Mounted!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment