Created
August 8, 2022 06:59
-
-
Save joanteixi/d9cba6e8ffad57c24b3af531e34801fe to your computer and use it in GitHub Desktop.
Databricks mount Azure Storage with pyspark version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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