How to Mount Azure Storage to Azure Databricks23 Nov 2020
I found multiple articles on how to mount an Azure Storage account in Azure Databricks, but most of them refered to using the Azure Key Vault which I do not want to setup at this time. So I decided to continue my quest as I required the storage account and container to be mounted for me to read the *.sas7dbat files into a Dataframe. I also could not find clear instructions on how to use the Databricks CLI in Azure Databricks.
First we will need to generate a SAS Token, which we can achieve by following this guide by June Castillote here.
I prefer to create a new Scala Notebook for the next part, so that I can save it and remember how I achieved this in the future. With the below script we start off by creating all the required variables for the actual mounting function. For a more complete guide see below link in the External Links for the full article by Gauri Mahajan
val containerName = "<Enter Container Name Here>" val storageAccountName = "<Enter Storage Account Here>" val sas = "<Enter SAS Key Here>" val config = "fs.azure.sas." + containerName+ "." + storageAccountName + ".blob.core.windows.net"
Once all the parameters is set, we can go ahead and mount the storage container into Azure Databricks. Remeber to change the mount name in the below script.
dbutils.fs.mount( source = "wasbs://" + containerName + "@" + storageAccountName + ".blob.core.windows.net/", mountPoint = "/mnt/<Enter Unique Mount Name Here>/", extraConfigs = Map(config -> sas))
Once we have our Storage Account mounted, we can start exploring the data in these mounts. First off lets look at all of our mapped mounts.
If you want to have a look at what files are in our Storage Account, you can use the below script.
dbutils.fs.ls("/mnt/<Enter Unique Mount Name Here>")
And if for any reason you want to unmount the Storage Account you can use the below script.
dbutils.fs.unmount("/mnt/<Enter Unique Mount Name Here>/")
Disclaimer: Content is accurate at the time of publication, however updates and new additions happen frequently which could change the accuracy or relevance. Please keep this in mind when using my content as guidelines. Please always test in a testing or development environment, I do not accept any liability for damages caused by this content.